View Single Post
Posts: 82 | Thanked: 214 times | Joined on Jan 2010 @ Cape town
#34
Originally Posted by SPARTAN563 View Post
Hi,
Sounds like you're making some good progress, despite the scourge that is exams

What I understand with regards to threading (bear in mind this is coming off a Win32/C# background) is that the following happens: for each core in the device a single (not necessarily your application's thread) can be run at any one time. i.e. if you have a dual core processor then 2 threads can be run concurrently without blocking one another. What the OS/Kernel does is simply blocks threads as required to give the illusion that they are all running simultaneously.

So, on the N900 (with it's little single core processor) you can run at most 1 thread at any one time. The best way to allow a "multithreading" system to work then is to make sure that the operating system prioritises your UI threads and other such things above your worker threads, this will lead to your worker threads being blocked more often and a bit of a general slowdown in terms of processing speed BUT your UI should remain perfectly usable while that is happening. Another alternative, without dropping the priority of your worker threads, is to make use of Sleep() function calls within them whenever they are likely to have nothing to do for a bit. Those Sleep() calls will be intercepted by the kernel and it will block that thread's execution for as long as it needs to in order to allow other threads to get some work done.

Just another thing that you may not expect when coding a multithreaded app is that the user is likely to go "usable UI = can do stuff", which from a coding perspective isn't always the case. You may want to make sure that your app can handle multiple different operations at the same time, say the user opening one email, then deciding that actually that wasn't the one they wanted and clicking on a different one (while your background thread would be loading the email they clicked on).

Overall though, good luck and I really look forward to being able to test it out, it certainly sounds impressive

Best Regards,
SPARTAN563
Hey SPARTAN563 - I take it you're from Stellenbosch, South Africa? Well - they aren't really many other Stellenbosch's around... Greetings from Cape Town in that case

Indeed - and that's what makes this case so peculiar. My architecture is split between a backend (that handles retrieving mails and updating a database) and the frontend (that is the GUI). The GUI isn't very threaded - it's essentially not needed. The "expensive" operations that I have complete so quickly (and should scale nicely too), that adding in the complexity of threads, callbacks and the like was just not necessary in most cases. The only thing in the GUI which is threaded is the search feature. Which works like a charm.

The backend is a different case all together. 99.99% of the time, it is blocking on IO (The N900's connection will generally be too slow to saturate the processor with the work I'm doing) and thus it's highly threaded. Each account gets its own thread to run in, and it receives (and sends) info to the front end via DBUS, which is threaded again.

Now, the DBUS thread essentially does nothing besides sit around and wait for events to happen - it should certainly not be blocking anything by using 100% of the CPU. But it appears to stop my other threads from running. On my desktop, a specific function call was needed, which essentially tells Python (which has the horrible Global Interpreter Lock) to allow other threads to run in the background while the main event loop is chugging along.

If I remove the DBUS bit everything works, but DBUS is a pretty integral component... So I'm going to have to find a way around this... Probably a platform specific oddity...


PS) Don't suppose you're studying - Know anyone up at UCT?