Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 12, 2009 "waking up" a thread | ||||
---|---|---|---|---|
| ||||
Is there a way to make the current thread sleep for a given amount of time, while having the possibility of another thread "waking it up" earlier? |
August 12, 2009 Re: "waking up" a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to funog | On Wed, 12 Aug 2009 13:00:22 -0400, funog <funog@ifrance.com> wrote:
> Is there a way to make the current thread sleep for a given amount of time, while having the possibility of another thread "waking it up" earlier?
Create a mutex/condition pair, then have one thread wait on the condition with a timeout.
The second thread signals the condition to wake it up early.
If you are using D1, then you have to use Tango (I think), and the classes are tango.core.sync.Mutex and tango.core.sync.Condition
If you are using D2, then they are in druntime, probably core.sync.Condition and core.sync.Mutex, not sure though.
-Steve
|
August 13, 2009 Re: "waking up" a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer Wrote:
> On Wed, 12 Aug 2009 13:00:22 -0400, funog <funog@ifrance.com> wrote:
>
> > Is there a way to make the current thread sleep for a given amount of time, while having the possibility of another thread "waking it up" earlier?
>
> Create a mutex/condition pair, then have one thread wait on the condition with a timeout.
>
> The second thread signals the condition to wake it up early.
>
> If you are using D1, then you have to use Tango (I think), and the classes are tango.core.sync.Mutex and tango.core.sync.Condition
>
> If you are using D2, then they are in druntime, probably core.sync.Condition and core.sync.Mutex, not sure though.
>
> -Steve
>
Thanks for your answer.
If there is a way without tango I am interested.
|
August 13, 2009 Re: "waking up" a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to funog | On Thu, 13 Aug 2009 02:59:39 -0400, funog <funog@ifrance.com> wrote:
> Steven Schveighoffer Wrote:
>
>> On Wed, 12 Aug 2009 13:00:22 -0400, funog <funog@ifrance.com> wrote:
>>
>> > Is there a way to make the current thread sleep for a given amount of
>> > time, while having the possibility of another thread "waking it up"
>> > earlier?
>>
>> Create a mutex/condition pair, then have one thread wait on the condition
>> with a timeout.
>>
>> The second thread signals the condition to wake it up early.
>>
>> If you are using D1, then you have to use Tango (I think), and the classes
>> are tango.core.sync.Mutex and tango.core.sync.Condition
>>
>> If you are using D2, then they are in druntime, probably
>> core.sync.Condition and core.sync.Mutex, not sure though.
>>
>> -Steve
>>
>
> Thanks for your answer.
> If there is a way without tango I am interested.
Yes, use D2.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation