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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:04:29+00:00 2026-06-06T20:04:29+00:00

I have a multithreaded program which uses pthread mutexes for synchronization on few integers.

  • 0

I have a multithreaded program which uses pthread mutexes for synchronization on few integers.

Of course it doesn’t scale well.

I read that the best way to share data is to eliminate ALL shared data – but what can I do if I need that overall “task count” (which is determined by shared integer(s)) shouldn’t be larger than this value? Consider that simple divide this integer between threads doesn’t work – one thread can run faster than others and stops when other continue working.

Also, using atomic operations on shared integer doesn’t work too – when thread count is huge, performance degrade because of write sharing.

Update: Its very undesirable to suspend threads, I need not only scalability but also deterministic time of delays in threads.

  • 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-06T20:04:31+00:00Added an answer on June 6, 2026 at 8:04 pm

    Give each thread its own counter. (Either in thread-local storage or on a page dedicated to that thread to make sure you don’t have bouncing cache lines.) When you need to provide an “overall task count”, have a control thread read the counters from all the other threads and sum them up in one place.

    If you want a perfect count, you could tell all the threads to suspend working. If you don’t mind the count being close but not perfect let them keep running. Since each thread only ever writes its own data it ought to run significantly faster than using a mutex on a shared counter. Integer writes are atomic on nearly all platforms except SPARC; if you don’t care about SPARC, you don’t need to do anything to prevent partial-writes to integers.

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

Sidebar

Related Questions

I have a speed critical multithreaded program which involves data in a tree structure.
I have an existing multi-threaded C++ program which uses a pool of sockets for
I have a multithreaded openCV program that uses 4 threads to do the following:
I have written a multithreaded program which does some thinking and prints out some
I have a multithreaded C program, which consistently generates a segmentation fault at a
I have a multithread linux program which uses epoll(7). The epoll(7) man page says
I have a long-running multithreaded program, and I'd like to occasionally like to call
I have a (C#) genetic program that uses financial time-series data and it's currently
I'm writing a multithreaded program, which would crash when a particular exception was thrown.
I have implemented a multi-threaded program which involves spawning a thread for each user,and

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.