
Thanks both to Geert and Ben for the quick reply.
join() waits for the thread to *end*. This should be done after the threads have been told to Stop().
I thought Java's join() was exactly the same.
Here are the bugs I found:
- Runnable::_running is read and written from multiple threads without use of a mutex. - The result of QueueAccessor::Pop is undefined if
is empty. Perhaps it should throw in this case? - The return type of QueueAccessor::Size should be std::queue<QueueItem>::size_type (which I think is std::size_t). - QueueAccessor::Size doesn't lock the mutex for the queue.
- Reader::Do busy-waits for input. It should wait on a condition variable instead. (Condition variables
functions equivalent to the wait, notify and notifyAll methods that Object has in Java.) Worse, when the reader is asked to stop, Reader::Do may never return to Worker::Run and so the thread will never stop. - CommandQueueTest.hpp doesn't include <iostream>. - #include <name> is reserved for use with system
Yeah I caught the problem when I had another look at the code earlier - I don't know what I was thinking. the queue provide headers.
You should use #include "name" for including your own headers. - Identifiers that include "__" are reserved for the use of the implementation. You must not use them. - Many member variables are protected when they should be private.
I have fixed most of the above and the program now works.
Ben.
Cheers for pointing out the bugs much appreciated. mcgiv ___________________________________________________________ BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk