in reply to Two threaded program

I don't see why you can't do this all in one thread, as tasks are not parallel, but here's a couple of notes. Instead of checking variable value in a loop, use cond_wait and cond_signal (see threads::shared). Wrap read/write loop into eval block, so you could catch any errors and still send signal to waiting thread to exit.