Is GHashTable (glib2) thread safe?
Asked Answered
D

1

12

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

Dorolice answered 12/1, 2012 at 15:42 Comment(1)
why someone would vote up this question as too localized ? This is good, reasonable and fair question.Germanism
Z
17

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.

Zante answered 12/1, 2012 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.