
I apologize if this gets posted more than once. I found the group on
GMane, tried to post, joined the email list, then tried to post several
times but still have yet to see it show up.
I'm learning C++ and found a tutorial on threads with Boost on Dr.
Dobb's site. I've copied the code from this url:
http://www.ddj.com/cpp/184401518?pgno=5
It's supposed to fill a buffer with data on one thread and remove data
on the other thread. I would expect it to add data and remove at
almost the same time but when I run it, it adds 10 items, then removes
them, then adds ten again, and so on. It's never adding and removing
in an "interleaved" fashion. I've also tried the same with simple
counters where both threads count to ten, but it doesn't seem to make a
difference. It seems no matter how I set it up, one thread either
completes, or runs until it has to stop for a mutex, then the other
thread runs. It seems that there is never a case of both threads
running at the same time. I've never had trouble doing this in Perl
with fork() so I'm not at all sure what could be going wrong.
As I said, it's not just the program below, it seems to be any program
that uses more than one thread.
Am I doing something wrong or is there a setting I need to change?
I'm compiling it with "g++ -lboost_thread mthrd.cpp -o mthrd
&& ./mthrd";
Thanks!
Hal
------
#include