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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:39:44+00:00 2026-05-16T15:39:44+00:00

I’m working on a simulation project using c++ on both windows and linux. There

  • 0

I’m working on a simulation project using c++ on both windows and linux.

There will be several thousand objects (Perhaps 3000-5000) in the simulation. In plan to have several threads performing actions on the objects so that it makes good use of multi core machines, for example one thread handling movement and location of the objects, one (or more) handling interaction between the objects, one handling creation of new objects.

However this will require synchronization between the threads to ensure it works properly. So I was thinking that each object should contain a (pthread mutex / CRITICAL_SECTION) depending on the platform, and then each thread can lock the objects it currently working on. Because there are a lot of objects contention should be rare so it should be fast.

So my first question is are 3000-5000 pthread mutexes or windows critical sections too many? I don’t know what limits both systems have. Or is there are better way to achieve this?

My second question is about data structures to hold the objects. Because objects can be created and “die” I feel the best way is to store a “list” of active objects that the work threads can iterate through. A c++ list is not thread safe though. If one of my threads deleted an object I would need to synchronize that with another object doing “next()” on the list. Also I’d need to ensure that the “next” object was locked before moving my iterator to it so I’d need some kind of global lock on the whole collection which I’d have to obtain before inserting / deleting objects but also before moving to the next object on a thread.

This seems rather painful and potentially slow. Is there are better way?

  • 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-16T15:39:45+00:00Added an answer on May 16, 2026 at 3:39 pm

    Instead of having the threads perform different actions on the objects, why not have each thread work on different objects? It sounds like you’re doing particle collisions. I worked on a project similar to this, although mine wasn’t threaded. But if you can group your objects into ‘spaces’, each thread can work on its own space and pass objects from one space to the other. You’re going to be killing your performance if you have 1 thread doing position tracking, and 1 thread doing collision calculations, because those calculations are very tightly coupled. Thread is (generally) only good when one thread isn’t directly dependent on the others.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT

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.