What is the best way to kill a thread when it pleases the owner (main thread)? The background is playing audio files. The playback happens in a separate thread so the owner can keep on listening to events triggered by the user (like stop, pause). I have to queue audio files, wait until one has finished, then play the next etc. Communicating between threads does not work with this technique:

Owner:
// create thread ...
...
auto isFinished = receiveOnly!bool();

Thread:
// play file ...
if (finished) {
  ownerTid.send(true);
}

Of course, now Owner waits until it receives the message and is deaf to any user input until Thread has finished, thus there is no way to interrupt the playback. Is there a simple and elegant D way to solve this? Slots are thread local so the observer doesn't know what's going on in another thread, does it?

Reply via email to