Async messages to a thread.
lindenk
ztaticnull at gmail.com
Mon Jul 29 10:35:45 PDT 2013
On Monday, 29 July 2013 at 17:26:55 UTC, Sean Kelly wrote:
> 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.
The blocking function will sometimes be socket IO, it's set up to
get data from whatever it is set to. That sounds promising
though, I could set it up to do that when it is socket IO then
have it poll when it isn't. Thanks!
More information about the Digitalmars-d-learn
mailing list