On Wednesday, 22 July 2015 at 15:41:06 UTC, Alex Parrill wrote:
On Wednesday, 22 July 2015 at 14:28:48 UTC, Chris wrote:
What would be the best way to manage different threads (spawned via std.concurrency), e.g. to tell them to stop at once, once a new command comes in? A thread pool? How would that look like in D? I feel my knowledge of D threads is still a bit limited.

`std.parallelism` includes a TaskPool class [1] and a taskPool property [2], but they spawn their own threads.

I'm not sure why you need a thread pool to tell std.concurrency threads to stop; why not send a stop message to each of them?

[1]: http://dlang.org/phobos/std_parallelism.html#.TaskPool
[2]: http://dlang.org/phobos/std_parallelism.html#.taskPool

Thanks. I'm dealing with "nested" threads at the moment.

main
{
  spawn(thread1)
  {
    // Does some processing
    spawn(thread2)
    {
      // Plays audio
    }
  }
}

If main receives a signal, all threads should stop immediately (thread1 and thread2).

Reply via email to