M
Mike
Greetings,
We have a synchronization scenario where we would like to ensure that
it is safe to exit the main application before actually exiting.
The scenario consists of one or more timers (or threads) that are
running that are in mid-stream doing their assigned tasks, such as, for
example, saving to an XML file.
Periodically, when exiting our XML output is corrupted, the save was
incomplete. So the next time into the application, we have what is in
effect an invalid format, even though it was one (or more) of the
records that failed to write.
So, we would like to give these timers (or threads) an opportunity to
finish what they are doing and signal to the application that it is
safe.
We've been thinking about the problem. Semaphores looked like a
potentially promising synchronization object, for example, a count
associated with the timers running. However, there does not appear to
be a means of querying a Semaphore for current or available count, so
probably not the greatest fit for the problem at hand.
Perhaps also Mutex. One mutex per timed event and if the application
detects that any of the mutexes are consumed, then it is not safe to
exit.
The opposite end of that relationship, of course, is the application to
somehow signal its intention to exit in order for the timers (or
threads) to not fire up again.
Anyways, this is the thought process. How feasible is this, has anyone
done it, etc, etc? Thanks in advance.
Best regards,
Michael
We have a synchronization scenario where we would like to ensure that
it is safe to exit the main application before actually exiting.
The scenario consists of one or more timers (or threads) that are
running that are in mid-stream doing their assigned tasks, such as, for
example, saving to an XML file.
Periodically, when exiting our XML output is corrupted, the save was
incomplete. So the next time into the application, we have what is in
effect an invalid format, even though it was one (or more) of the
records that failed to write.
So, we would like to give these timers (or threads) an opportunity to
finish what they are doing and signal to the application that it is
safe.
We've been thinking about the problem. Semaphores looked like a
potentially promising synchronization object, for example, a count
associated with the timers running. However, there does not appear to
be a means of querying a Semaphore for current or available count, so
probably not the greatest fit for the problem at hand.
Perhaps also Mutex. One mutex per timed event and if the application
detects that any of the mutexes are consumed, then it is not safe to
exit.
The opposite end of that relationship, of course, is the application to
somehow signal its intention to exit in order for the timers (or
threads) to not fire up again.
Anyways, this is the thought process. How feasible is this, has anyone
done it, etc, etc? Thanks in advance.
Best regards,
Michael