How to stop the Threadmill

Dicebot m.strashun at gmail.com
Mon Jan 28 02:33:30 PST 2013


On Monday, 28 January 2013 at 10:18:27 UTC, Chris wrote:
> I am sure this has been asked before, but I couldn't find a 
> solution or a hint via Google: I use a separate thread to play 
> a sound file. Everything works fine, except that I cannot tell 
> the thread to stop what it is doing. It refuses to receive 
> messages while it is doing what it's doing (even if I just run 
> a simple test function with a long for-loop to make sure it's 
> not a hardware issue). I should probably add that the thread is 
> started from within the main loop of a socket that waits for 
> input. If the input is "stop" it should tell the play-thread to 
> stop, but nothing happens.
> I can imagine that the thread is no longer visible to the 
> main-thread, although I keep a reference to it. Any help or 
> hint will be appreciated.

Wild guess: sounds likely that your "play thread" does some 
blocking processing and just never pauses to process messages. 
You need to explicitly say to the thread when to have a pause in 
a job and check incoming messages. You can kill the thread 
externally but that would be an abnormal termination, no 
destructors called and all the bad stuff.

That said, I assume some typical pthread-based code, details may 
differ depending on the implementation.


More information about the Digitalmars-d-learn mailing list