openframeworks/openFrameworks — pull request #1031 by danomatika (2012-03-04 04:10:39+00:00)
Title: ofThread rewrite & ofSemaphore typedef

Howdy all,

I started rewriting ofThread in Detroit but stopped do to other priorities. Now it's essentially done and much cleaner then what I started with .. wheew. In any case, it's been rewritten using Poco::Thread and Poco::Runnable and the resulting code is much cleaner and hopefully easier to maintain ... no platform specific stuff.

Poco::Thread provides some nice things like unique ids, thread sleep(), yield(), and knowing which thread you are in. The verbosity prints now uses an ofLog module with the current thread id and the mutex lock()/unlock() verbose prints now tell you if the thread itself or another thread is trying to lock/unlock it.

Sorry Kyle, getCurrentThread() returns a pointer. How else can you either return an object or not if there isn't one? :D

In any case, I tested this with the threadExample and it's working fine. I'd appreciate others trying it out, especially on Windows. I noticed a bug last week on Windows where starting the same thread multiples times *spawn new threads*. I assume Poco::Thread dosen't let that happen so this bug should be gone.

Also, from talking with Damian about what's needed for Threads, I added an ofSemaphore typedef of Poco::Semaphore.

P.S. The commenting comes from me working out how ofThread is supposed to work internally by reading the code for both the rewrite and the site documentation. I normally do this when I write an API and I figured I'd leave it in for now. I can remove it if the "no header commenting" unwritten rules is in force ...