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 914393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:42:40+00:00 2026-05-15T17:42:40+00:00

I have a scenario where, at certain points in my program, a thread needs

  • 0

I have a scenario where, at certain points in my program, a thread needs to update several shared data structures. Each data structure can be safely updated in parallel with any other data structure, but each data structure can only be updated by one thread at a time. The simple, naive way I’ve expressed this in my code is:

synchronized updateStructure1();
synchronized updateStructure2();
// ...

This seems inefficient because if multiple threads are trying to update structure 1, but no thread is trying to update structure 2, they’ll all block waiting for the lock that protects structure 1, while the lock for structure 2 sits untaken.

Is there a “standard” way of remedying this? In other words, is there a standard threading primitive that tries to update all structures in a round-robin fashion, blocks only if all locks are taken, and returns when all structures are updated?

This is a somewhat language agnostic question, but in case it helps, the language I’m using is D.

  • 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-15T17:42:41+00:00Added an answer on May 15, 2026 at 5:42 pm

    I don’t know if there’s a standard way to do this. However, I would implement this something like the following:

    do
    {
        if (!updatedA && mutexA.tryLock())
        {
            scope(exit) mutexA.unlock();
            updateA();
            updatedA = true;
        }
    
        if (!updatedB && mutexB.tryLock())
        {
            scope(exit) mutexB.unlock();
            updateB();
            updatedB = true;
        }
    }
    while (!(updatedA && updatedB));
    

    Some clever metaprogramming could probably cut down the repetition, but I leave that as an exercise for you.

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

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 503k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This can be done easily with the CSS property text-overflow:… May 16, 2026 at 2:45 pm
  • Editorial Team
    Editorial Team added an answer You have to explicitly return the data from fetch_quote function.… May 16, 2026 at 2:45 pm
  • Editorial Team
    Editorial Team added an answer You need to use margin:auto with specified width like this:… May 16, 2026 at 2:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a scenario where page A can navigate to page B, and page
I have a set of data that has been displayed as just a simple
The current issue im facing is comes from the following scenario. I have a
I have a scenario where I have a list of classes, and I want
I have a scenario where I'm working with large integers (e.g. 160 bit), and
I have a scenario where I would like to select rows from a table
I have 4 binary bits Bit 3 Bit 2 Bit 1 Bit 0 Normally
Ok so i have a DECIMAL field called Score. (e.g 10.00 ) Now, in
Here is my scenario: I am building a location finder using the iPhone mapkit.
Tools: SQL2000/5/8, .NET 3.5, C# I have come across an application that has two

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.