Opened 14 years ago
Closed 14 years ago
#1929 closed Bugs (fixed)
Borland/Codegear C++ 2007 creating boost::thread fails at initialisation of membervar boost::thread::thread_info
Reported by: | Owned by: | Anthony Williams | |
---|---|---|---|
Milestone: | Boost 1.36.0 | Component: | thread |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | Cc: | me@… |
Description
I'm attempting to create a thread in Borland/Codegear C++ 2007 (win32) by means of code similar to this:
class Threaded { volatile bool _quit; boost::thread _thread; public: Threaded() : _quit(false), _thread(boost::ref(*this)) {} void operator()() { while (!_quit) /* do stuff here */; } };
The results of several debugging sessions:
However as soon as the constructor of boost::thread gets invoked it will call boost::thread::make_thread. This allocates some heap memory using the Windows API and uses an in-place new to construct a detail::thread_data<T> in that memory. The allocation and construction seem to work out very well.
As soon as boost::thread::make_thread_info returns however it seems to fail to assign the pointer to member variable thread_info in the constructor.
I tried the below patch for debugging purposes, to see what happens. Somehow the new variable (tinfo
) remains NULL (all heap memory is initialised to zero while debugging, hence the NULL) however. Thus it seems that this compiler (borland) somehow fails to generate code that properly assigns the pointer to boost::thread's member variables.
However, somehow assigning the value of tinfo
to an on-stack variable does yield the correct pointer, while at the time the debugger says that tinfo
is still NULL, even though assigning it to another pointer yields a non-NULL (and correct) value. So maybe it's pointer value is kept in a register but only gets assigned to stack based variables but not to member variables?
What's even more strange is that compiling a minimal test case outside of the IDE (using bjam) produces code that works. Unfortunately I cannot use bjam for my project as it depends on Borland's VCL GUI library (if it's possible to use bjam with Borland's VCL anyway please tell me where to look/what to do, as up till now I've only failed miserably and have little experience with bjam anyway).
Thus this leads me to believe that something differs in the compiler options, I haven't got the slightest clue what it could be though. I've got all optimisations turned off. Although I have no clue how to know what command line options the IDE is calling the compiler with, so I cannot compare it.
-
boost/thread/win32/thread.hpp
196 196 }; 197 197 198 198 mutable boost::mutex thread_info_mutex; 199 detail::thread_data_base* tinfo; 199 200 detail::thread_data_ptr thread_info; 200 201 201 202 static unsigned __stdcall thread_start_function(void* param); … … 214 215 } 215 216 #else 216 217 template<typename F> 217 static inline detail::thread_data_ ptrmake_thread_info(F f)218 static inline detail::thread_data_base* make_thread_info(F f) 218 219 { 219 220 return detail::heap_new<thread_data<F> >(f); 220 221 } … … 238 239 #else 239 240 template <class F> 240 241 explicit thread(F f): 241 thread_info(make_thread_info(f)) 242 tinfo(make_thread_info(f)), 243 thread_info(tinfo) 242 244 { 243 245 start_thread(); 244 246 }
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
After some further experimenting I found that thread-borland-workaround.patch fixes the problem, though only for the construction part of boost::thread. As soon as you call boost::thread::join it'll segfault.
comment:3 by , 14 years ago
Btw thread-borland-workaround.patch only works because it moves the pointer assignment out of the IDE compiled code into bjam compiled code.
PS I also found this thread on comp.lang.c++ on what seems to be the exact same problem: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/e532172a82d20674
comment:4 by , 14 years ago
Component: | None → thread |
---|---|
Owner: | set to |
comment:5 by , 14 years ago
I found that these are the compiler options that are used (on all source files) when I compile using the IDE:
bcc32.exe -D_DEBUG;NO_STRICT -D_RTLDLL;USEPACKAGES -I"c:\program files\codegear\rad studio\5.0\include";"c:\program files\codegear\rad studio\5.0\include\dinkumware";"c:\program files\codegear\rad studio\5.0\include\vcl";..\..\..\Bureaublad\proia3\src\opengltest;"c:\program files\codegear\rad studio\5.0\include\Indy10";C:\boost_1_35_0 -y -v -vi- -k -r- -c -tWM -tW -H=Debug\borlandgltest.pch -oDebug\gldraw.obj -w-par -Od gldraw.cpp
This the linker command used:
ilink32.exe -L"c:\program files\codegear\rad studio\5.0\lib\debug";"c:\program files\codegear\rad studio\5.0\lib";"c:\program files\codegear\rad studio\5.0\lib\obj";"c:\program files\codegear\rad studio\5.0\lib\psdk";..\..\..\Bureaublad\proia3\src\opengltest;"c:\program files\codegear\rad studio\5.0\lib";"c:\program files\codegear\rad studio\5.0\lib\Indy10";"C:\Documents and Settings\All Users\Documenten\RAD Studio\5.0\DCP";Debug -j"c:\program files\codegear\rad studio\5.0\lib\debug";"c:\program files\codegear\rad studio\5.0\lib";"c:\program files\codegear\rad studio\5.0\lib\obj";"c:\program files\codegear\rad studio\5.0\lib\psdk";..\..\..\Bureaublad\proia3\src\opengltest;"c:\program files\codegear\rad studio\5.0\lib";"c:\program files\codegear\rad studio\5.0\lib\Indy10";"C:\Documents and Settings\All Users\Documenten\RAD Studio\5.0\DCP";Debug -lDebug -v -Gn -GA"C:\Documents and Settings\Giel van Schijndel\Mijn documenten\C++\proia3\src\opengltest\vfs24D.tmp"="C:\Documents and Settings\Giel van Schijndel\Mijn documenten\C++\proia3\src\opengltest\borlandgltest.res" -GA"C:\Documents and Settings\Giel van Schijndel\Mijn documenten\C++\proia3\src\opengltest\vfs24E.tmp"="C:\Documents and Settings\Giel van Schijndel\Mijn documenten\C++\proia3\src\opengltest\form1.dfm" -aa c0w32.obj vcl.bpi rtl.bpi vclx.bpi memmgr.lib sysinit.obj Debug\borlandgltest.obj Debug\devicecontext.obj Debug\form1.obj Debug\glcontext.obj Debug\gldraw.obj , Debug\borlandgltest.exe , Debug\borlandgltest.map , import32.lib cp32mti.lib , , "C:\Documents and Settings\Giel van Schijndel\Mijn documenten\C++\proia3\src\opengltest\vfs24D.tmp"
comment:6 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This issue appears to be due to the lack of abi_prefix.hpp and abi_suffix.hpp. I've added these to trunk in revision 45865, which should fix the problem.
Note, I've tested this with both trunk and 1.35 and it happens with both.