Search code examples
cmultithreadingglib

Is GLib's GHashTable thread-safe for read-only accesses from multiple threads?


I want to create a GHashTable in program's initialization, which would be later concurrently accessed for reading only by newly created threads.

Is it safe to do so without a lock?


Solution

  • In general, mutual exclusion is only needed when you could be modifying data concurrently with reading or modifying in another thread. If all accesses (after the hash table is filled in during initialization) are just reading, there's no need for locks.