Async messages to a thread.

Sean Kelly sean at invisibleduck.org
Mon Jul 29 10:26:45 PDT 2013


On Jul 29, 2013, at 10:07 AM, lindenk <ztaticnull at gmail.com> wrote:

> After a bit more research it looks like everyone else uses -
> 
> while(checkIfRunning())
> {
>    // block with timeout
> }
> 
> which leads me to believe this might not be possible or standard. Although, should something along the lines of this be possible?

It sounds like you're maybe doing socket IO?  In those cases, you can open a pipe for signaling.  select() on whatever other socket plus the read end of the pipe, and if you want to break out of the blocking select() call, write a byte to the pipe.  Ultimately, std.concurrency should get some socket integration so data can arrive as messages, but that will never be as efficient as the approach I've described.

> Process p = new Process();
> p.doTask(p.func()); //create new thread and start function
> 
> // do stuff until this needs to exit
> 
> p.stop(); // halt running function,
> p.cleanup(); // call a clean up function for func's resources
> p.kill(); // forcibly kill the thread

Forcibly killing threads tends to be a pretty bad idea if you intend to keep running after the thread is killed.  It can even screw up attempts at a clean shutdown.


More information about the Digitalmars-d-learn mailing list