Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Incrementing Semaphores on process termination

104 views
Skip to first unread message

nrieger

unread,
Aug 2, 2005, 10:00:05 AM8/2/05
to
Hi,

I'm using several semaphores (max val 1) for IPC:

hnd = CreateSemaphore (NULL, 1, 1, "SEM-1");
....
result = WaitForSingleObject(hnd, INFINITE);

If a process is killed or stopped while it holds the semaphore (val=0), the
semaphore is not incremented by Windows (process cleanup ?).

Doesn't windows cleanup (increment semaphore by process' descrements) on
process termination ?

I'm using Windows XP, 2000, 2003 Server, each process is a "console
Application" developed with VC++ 6.0.
Each assistance is welcome and appreciated.
Thanx a lot.

Terrence

unread,
Aug 2, 2005, 2:48:25 PM8/2/05
to
If you need to know that a process was terminated, get the HANDLE for the
process and use that to wait.

Instead of using a semaphore with count 1, use a mutex, because
WAIT_ABANDONED will be returned in the event that the mutex-holder is
terminated.

A semaphore is not "held" like a mutex is held. It is just a
waitable-atomic-counter.

"nrieger" <nri...@discussions.microsoft.com> wrote in message
news:A77D8544-DD8F-4EC6...@microsoft.com...

nrieger

unread,
Aug 3, 2005, 8:40:38 AM8/3/05
to
Thanx a lot,
I changed from semaphore to mutex. Works fine, thanx a lot.
I thought mutex is only used for thread sync (like critical sections),
didn't know
that they can be used across processes.
0 new messages