Jump to content
  • Advertisement
Sign in to follow this  
cignox1

Boost: shared_ptr and threads

This topic is 3833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, when I compile my program while including boost::thread, it says me that boost explicitly disabled threads. I suppose that this was done by shared_ptr (since it is the only other lib in my test project). If I try to undef BOOST_DISABLE_THREADS I get other errors. My question is: what do I need to do in order to use shared_ptr and boost::thread? Thank you!

Share this post


Link to post
Share on other sites
Advertisement
Hmmm, that's weird ... normally you need not do anything IMO. I use boost::thread and boost::shared_ptr together all the time, and I've never run into that problem.

Share this post


Link to post
Share on other sites
Ok, I though it was due to the fact that by default (IIRC) shared_ptr is not thread safe, but apparently it is not. I'm using Visual studio 2005, last version of boost, compiled simply by running bjam without parameters (it defaults to msvc). I'm using Windows Vista.

I've already used boost::thread, but never togheter with shared_ptr.

Thank you!

Share this post


Link to post
Share on other sites

Are you getting exactly the message
"Threading support unavaliable: it has been explicitly disabled with BOOST_DISABLE_THREADS"

?

If so, do a search through your project and through the boost source code for

define BOOST_DISABLE_THREADS

and figure out what's disabling it.

My likely suspicion is that it's disabled in user.hpp. Did you change it at all? Using shared_ptr doesn't disable threads, and IIRC it internally uses atomic increment/decrement for the refcount.

Share this post


Link to post
Share on other sites
This is the actual test of the error message:

Error 47 fatal error C1189: #error : "Threading support unavaliable: it has been explicitly disabled with BOOST_DISABLE_THREADS" C:\Users\alessandro.caviola.EMDSESRL\Documents\Visual Studio 2005\Projects\boost_1_34_1\boost\config\requires_threads.hpp 29

I didn't even know that a file user.hpp existed. Anyway, the code in that file is commented out (all the lines). I don´t know if during compilation some of them were uncommented. I was not able to find #define BOOST_DISABLE_THREADS in any of the files apparently related to thread or to shared_ptr, but I got many results. I could try to give them all a look...

Share this post


Link to post
Share on other sites
Hmmm, if you find that you get stuck too long trying to solve this mystery ... perhaps just upgrade to boost 1.35?
boost.thread has gotten some important changes in 1.35 ... some of them could break existing code ... so it might be better to convert to 1.35 early on rather than having to make the adjustments later when you've written more code.
Also, with some luck the problem might just disappear if you start from scratch with a fresh boost installation.

Share this post


Link to post
Share on other sites
There are two reasons I can think of:

1) You are compiling your project with the single-threaded runtime. Go to project settings, C/C++, Code Generation and select either "Multithreaded" or "Multithreaded DLL" (and, of course, the equivalent debug runtimes for your 'Debug' configuration).

2) Boost/config/user.hpp has BOOST_DISABLE_THREADS defined. This is the only legal place to define or undefine it, doing it any later will have undefined effects, so a quick #undef BOOST_DISABLE_THREADS in front of the boost headers does nothing at best.

Share this post


Link to post
Share on other sites
I got the latest version, but the sesults are the same... In user.hpp the #define BOOST_DISABLE_THREADS is commented out, runtime libraries are multithreaded (I tried with both the static linked and the dynamic linked ones).

A question: to use threads I only need to include <boost/thread.hpp>, right?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!