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

  • Home
  • SEARCH
  • 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 4108744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:41:58+00:00 2026-05-20T21:41:58+00:00

Hello I built a hash table in C. I have unit tested it enough

  • 0

Hello I built a hash table in C. I have unit tested it enough to be confident it works. The thing is that the data structure will be dynamicly linked to code that I did not write and may be using threads. So I need to synchronize it so it’ll work correctly for theoretically any number of threads concurrently modifying/ reading it. After studying the pthread mutex API I did the following

Declared a static global variable:

static pthread_mutex_t lock;

On HashTable_init (which is always called before the hash table is used) I init it:

pthread_mutex_init(&lock,NULL);

On each function that reads/writes the structure I put an lock at start:

pthread_mutex_lock(&lock);

and unlock at the end:

pthread_muter_unlock(&lock);

Is that enough to make an data structure synchronized? ( as at the moment my program hangs ).

Thank you

  • 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-05-20T21:41:59+00:00Added an answer on May 20, 2026 at 9:41 pm

    It might be not enough. With locking each and every method, you ensure that the internal structure of your container is consistent at any point; but some uses of the container might require more than that.

    Consider the following rather simple case: in one thread, you found an item by certain key and start editing it. When find() completes, it releases the lock and then returns a reference to an item. Meanwhile the lock can be acquired and another thread might for example delete this item, quite unexpectedly for the first thread.

    Designing and developing a good and safe concurrent container is not an easy thing. I would recommend you instead look for ready-to-use solutions.

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

Sidebar

Related Questions

I have written a printf() statement like below: printf(hello\n); this works fine when built
I have a Cocoa app send some data along with a SHA1 hash of
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello we have an SQL server application running over a low bandwith connection. We
I fought with the IDE and read around all day enough to learn that
The following C# program (built with csc hello.cs ) prints just Hello via Console!
I just built a cross compiler using crosstools mips-unknown-linux-gnu-gcc and I compiled a hello
Please help me with using the DrScheme built-in function filter. create a function hello
Hello is there any windows API function that would return if drive is writable.

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.