Unable to compile thread example on the document.
Hi,
I cannot compile the thread example listed on the document:
http://www.boost.org/libs/thread/doc/thread.html#Example
I'm using g++ 2.95.3 on a FreeBSD 4.x box. Here are the exact
environment and compile error messages:
% uname -a
FreeBSD XXX.foo.bar 4.5-PRERELEASE FreeBSD 4.5-PRERELEASE #0: Tue Jan 8 03:14:40 CST 2002 root@XXX.foo.bar:/usr/src/sys/compile/kernel.XXX i386
% g++ -v
Using builtin specs.
gcc version 2.95.3 20010315 (release) [FreeBSD]
% cat test_thread0.cpp
#include
On 2/4/02 12:02 AM, jeffhung@ms44.url.com.tw wrote:
I cannot compile the thread example listed on the document: http://www.boost.org/libs/thread/doc/thread.html#Example
[...]
boost::thread thrd(thread_alarm(secs));
[...]
test_thread0.cpp: In function `void run()': test_thread0.cpp:28: request for member `join' in `thrd', which is of non-aggregate type `boost::thread ()(thread_alarm)'
I've tried to figure out where the problem is and failed to find the definition of class thread. Do I miss something? Or, is it just a freebsd porting problem?
This is a bug in the example that has been fixed for the next upcoming Boost release. The web site will be updated soon. The problem line above is can be interpreted as a declaration of a function named thrd with a parameter of type thread_alarm named secs, rather than a declaration of an object named thrd. And the C++ rule is that if it can be a function declaration, then it is. The fix is to replace the line with these two lines: thread_alarm alarm(secs); boost::thread thrd(alarm); Hope that helps. -- Darin
participants (2)
-
Darin Adler
-
御風只配做笨木頭