Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GHashTable (glib2) thread safe?

I have multiple threads adding, modifying and looking up data in GHashTable. Is it threadsafe, or do I need to implement threadsafety myself?

like image 604
iseletsk Avatar asked Jan 12 '12 15:01

iseletsk


1 Answers

The documentation states this pretty clearly:

After calling g_thread_init(), GLib is completely thread safe (all global data is automatically locked), but individual data structure instances are not automatically locked for performance reasons. So, for example you must coordinate accesses to the same GHashTable from multiple threads.

So: no, the hash table is not thread safe.

like image 124
unwind Avatar answered Nov 16 '22 01:11

unwind