Thursday, June 12, 2008

Critical Sections and Mutexes

Ah, the joy of multithreading. I really miss the wxMutex and wxMutexLocker classes of wxWidgets, which unfortunately, I can't use for the wrappers (because they're wrappers and therefore they need to be as lightweight as possible. Linking to the wxWidgets library isn't exactly what I want).

The first decision I took was to use the SFML Mutexes class. Unfortunately, I stumbled upon the problem: If I include this for the wrapper, what will happen when one of the plugins actually uses the library? Would I get some duplicate definition? Should I copy the code and rename it?

Forget it. Enter google. I found two great resources for using Mutexes: (which included a copy of the pthreads manpage) and wikipedia. Lucky me, the wikipedia tutorial included a cross-platform version of implementing critical sections! And it's GFDL, alright!

Now let's see if I can find a good example of a cross-platform thread-safe sleep() function.

Update: Done. Now I can go back to work on thread-safety for the audio/video wrappers.

No comments: