Boost: shared_ptr and threads

Started by
9 comments, last by cignox1 15 years, 10 months ago
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!
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.
What platform are you on? What compiler + version?
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!

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.
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...
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.
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.
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
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?
No, boost.thread is one of the libraries that require you to build boost.

This topic is closed to new replies.

Advertisement