Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8635799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:03:52+00:00 2026-06-12T10:03:52+00:00

Are g_hash_table_lookup and g_hash_table_insert thread-safe? Can I use code like this: dict = g_hash_table_new();

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:03:53+00:00Added an answer on June 12, 2026 at 10:03 am

    No. From the Threads section of the GLib Reference Manual:

    GLib itself is internally completely thread-safe (all global data is automatically locked), but individual data structure instances are not automatically locked for performance reasons. For example, you must coordinate accesses to the same GHashTable from multiple threads. The two notable exceptions from this rule are GMainLoop and GAsyncQueue, which are thread-safe and need no further application-level locking to be accessed from multiple threads. Most refcounting functions such as g_object_ref() are also thread-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The C code #include <glib.h> //... GHashTable *hash = g_hash_table_new(NULL, NULL); GString val; g_hash_table_insert(hash,
G'day, Edit: While this question covers a situation that can arise in programming a
I would like to use JNDI to look up Kerberos SRV records in a
Programming in C, are there any techniques one can use to avoid (or at
Short version: is it safe to use ets:foldl to delete every ETS record as
This part of could should return always the same hash value to each Key
didn't find an answer to this. I like KeyedCollection, because it keeps the insertion
I want to use hash tables in my c program. I code: ... #include
Is there a way to grab the URL's hash value (e.g. the 35 in
When using GLib 1.2's GHashTable with the g_hash_table_foreach() method, is it safe to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.