Thread can not run concurrently with bind parameter
Hi All: It may be a simple question, but I have no idea now. So I want to post my question with you. Maybe you can help, thank you. It is about boost thread. I want to create a thread and pass a parameter to it. I found there are 2 ways in boost thread, they are: using bind, like *boost::thread thrd(boost::bind(&helloworld, "Bob"));* *thrd.join();* or construct a structure and do the following: *boost::thread thrd(helloworld("Bob"));* *thrd.join();* It works, really, like the demo code shown. But After I run 2 threads, I found 2 thread can not run concurrently. The second thread will blocked by the first thread. If the first thread never exit, the second thread never run. It is a very funny problem. But I really do not know what happen. Does anyone know about this topic? Thank you very much. -- With regards. Coofucoo Zhang
Hi there,
using bind, like boost::thread thrd(boost::bind(&helloworld, "Bob")); thrd.join();
I prefer bind.
The second thread will blocked by the first thread. If the first thread never exit, the second thread never run. It is a very funny problem. But I really do not know what happen. Does anyone know about this topic?
Please provide a code sample that shows your problems. Also, make sure you create the two threads first before you you call any join(). Since you are calling your thread function helloworld, I suspect you're using the threads to print out some text on the console. Some systems will provide a basic locking scheme when several threads accessing stdout file. Use an endless loop in your thread function and you'll see them running concurrently. Regards, Christian
HI Christian:
thank you for you reply. I have found the problem, it is very simple. That
is because I use join before I start next thread. So.......:P
On Mon, Jun 7, 2010 at 5:27 AM, Christian Henning
Hi there,
using bind, like boost::thread thrd(boost::bind(&helloworld, "Bob")); thrd.join();
I prefer bind.
The second thread will blocked by the first thread. If the first thread never exit, the second thread never run. It is a very funny problem. But I really do not know what happen. Does anyone know about this topic?
Please provide a code sample that shows your problems. Also, make sure you create the two threads first before you you call any join().
Since you are calling your thread function helloworld, I suspect you're using the threads to print out some text on the console. Some systems will provide a basic locking scheme when several threads accessing stdout file. Use an endless loop in your thread function and you'll see them running concurrently.
Regards, Christian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- With regards. Coofucoo Zhang
participants (2)
-
Christian Henning
-
coofucoo zhang