Are g_hash_table_lookup
and g_hash_table_insert
thread-safe? Can I use code like this:
dict = g_hash_table_new();
for (i = 0; i < N; i++) {
compute_A();
find_hash_of_A();
void *value = g_hash_table_lookup(dict, key);
struct MyStruct *obj;
if (!value) {
obj = (struct MyStruct *)value;
} else {
compute_obj
g_hash_table_insert(dict, key, obj);
}
do_something_with_obj
}
with #pragma omp parallel for
, or I need to use some other OpenMP pragmas?
At times I got an error in that loop. One thread version works fine.