Re: [boost] thread yield
by Peter Petrov other posts by this author
Sep 23 2005 6:00PM messages near this date
Re: [boost] [tools][bcp] using boost internally in other libraries
|
Re: [boost] [preprocessor][dmc] improved dmc conformance
SOURCE Jason Hise wrote:
> Alright, I will add some more context to the discussion. This is being
> used for a 'timeout lifetime' for the singleton library. The idea is
> that a singleton which is cheap to create but expensive to hold on to
> could automatically be destroyed if it goes unused a certain amount of
> time, and be recreated the next time it is needed. To implement this
> idea I create a timeout thread when the instance is created, and force
> that thread to sleep until the timeout time is reached. If at that
> point the timeout time has been extended, the thread sleeps again,
> otherwise it destroys the instance and exits.
>
> The problem is that if the process is exiting I would like to force the
> thread to wake up and time out early to ensure that the singleton get
> destroyed.
Instead of sleeping, use timed_wait on a condition variable. Upon
awakening, check the cause (which could be timeout, valid signal, or
spurious wakeup).
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
|