Yep. (N.b. I use the term mutex to refer to CRIT_SECT because it's in line with pthreads terminology).Ahh it seems that I can use InitialiseCriticalSection(), EnterCriticalSection(), LeaveCriticalSection() and DeleteCriticalSection(). This seems to be aimed at threads of the same process as opposed to mutex which is between threads on different processes.
You could pass a pointer to a struct containing all the data required for the thread, e.g.To be able for all the threads to access the threadBlocker it seems I must make it global, or either create a new object in which to encapsulate everything that get passed to the new threads. Or is it possible to pass more than one object to a new thread?
That said, I'd wrap CRIT_SECT up in a C++ object.Code:struct thread_stuff { char *something; int something_else; CRITICAL_SECTION* thread_lock; };
Scoped RAII locking also helps, especially when you have multiple return paths from a function where you locked your mutex.
Also:
Your "while some cond" loops should probably be turned into condition variable waits.
Presumably you're setting your "some cond" from one thread and then testing from another to see if there's work available, or whatever - you should probably use a condition variable & mutex to wait on the condition, rather than using sleep.
Side note: boost provides an OO mutex, condition variable, and scoped RAII lock.