Multithreaded GLib applications

Okay. I learned this the hard way: Never use the pthread API in glib applications. Use the GThread stuff! For example will the GList type reuse memory from the memory pool (the GAllocator stuff). This memory pool is locked using G_LOCK macros. If you didn’t launch g_thread_init(NULL), those macros won’t really lock the code-parts that ought to be locked. Therefor won’t the GList be threadsafe. So filling multiple glists in multiple threads can (and probably will) cause race conditions.

The GThread stuff will wrap pthread functions on platforms that use pthread as threading implementation. It doesn’t support the pthread_cancel() function. But then again, is the cancellation of threads not a clever thing to do. It’s better to implement cancelling of parallel procedures by checking some condition that might have been set by another thread (and returning or g_thread_exit in the thread that is to be cancelled).