Multithreading & Boost

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
C++ has no built in multithreading. (Well, the new standard coming out soon will, but that's irrelevant). Boost, which Civ4 uses, does. I looked up the boost docs for the version Civ4 is using, and you can bind functions to variables, and create a new thread, and use the functions with the new threads. But I could never get it to work fiddling around with the source. (I'd like the put the python calls in a separate thread, wherever they have no return value, to speed things up). I saw this example, but could not get it to work:

http://stackoverflow.com/questions/344101/multithreading-using-the-boost-library

Has anyone ever used the Boost Libraries to multithread, and had success?
 
Any chance of including a super-brief code example & setup instructions?
 
I think you might get sync problems if you have different parts of Python code run in separate threads... They still have shared objects.
 
I think you might get sync problems if you have different parts of Python code run in separate threads... They still have shared objects.


I'm less worried about the sync issues, and more worried about the implementation ATM.
 
I'm less worried about the sync issues, and more worried about the implementation ATM.

Your choice, but I think it's more than just technical problem solving that comes later - since it was not written to support threading in the first place, I don't think it's really doable.
And if you add a critical section lock on everything - not only will you not gain any performance improvement, but you'll slow the system down.
 
Your choice, but I think it's more than just technical problem solving that comes later - since it was not written to support threading in the first place, I don't think it's really doable.
And if you add a critical section lock on everything - not only will you not gain any performance improvement, but you'll slow the system down.

While I appreciate your pessimism, that was never my intended goal. I'm familiar with multi-threading, having some experiences with it in Java. Multi-threading at specific points, like heavy I/O operations, and python calls could provide significant speedups. But again, I'm not worried about the where, more as the how ATM.
 
While I appreciate your pessimism, that was never my intended goal. I'm familiar with multi-threading, having some experiences with it in Java. Multi-threading at specific points, like heavy I/O operations, and python calls could provide significant speedups. But again, I'm not worried about the where, more as the how ATM.

Yes, pessimism is one of my finest qualities :lol:

I'm interested in your results in any case. I'd be glad to see them.

If you have code that doesn't work, you could try posting it for the chance I might be able to assist.
I haven't used boost's threading library, but I did write multithreaded applications in C++, so maybe I can contribute...
 
Any chance of including a super-brief code example & setup instructions?

It's been awhile that I used it, but all you should have to do is to download the sdk and include the library so that the compiler understands the new functions. and you need to put the dll into the base bts folder (where the exe is). You need the 32 bit version because civ4 is 32bit.

I am sure the sdk has some code examples. There is also a book about Intel Threading Building Blocks that has all the basics, how to set parameters for optimal load balancing, etc.
http://www.amazon.com/Intel-Threading-Building-Blocks-Parallelism/dp/0596514808
maybe a library near you has it.

One of the total war games uses this threading library.
 
Top Bottom