Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Counting semaphore
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Le Chaud Lapin  
View profile  
 More options Mar 16 2003, 12:42 am
Newsgroups: comp.os.ms-windows.programmer.win32
From: unoriginal_usern...@yahoo.com (Le Chaud Lapin)
Date: 15 Mar 2003 21:42:06 -0800
Local: Sun, Mar 16 2003 12:42 am
Subject: Re: Counting semaphore

"v patel" <vipul.pa...@intel.com> wrote in message <news:TG8ca.5431$io.230820@iad-read.news.verio.net>...
> - Does this kernel object adjusts reference count to reflect abandonment by
> one of the processes

No.

Closing a handle and changing the reference count are two different
things.

You might imagine a situation where there is a system-wide semaphore
that is waited on by 9 processes and set to its intial value by a
10th.  The 10th process would have only one job - to set the initial
count of the semaphore and exit, but the programmer is sloppy so
CloseHandle will not be called before exit.  The other 9 processes
would then contend for access to the semaphore based on the initial
value.

So you can see that it would be conceptually inappropriate for the OS
to adjust the reference count simply because the handle was not
closed.

Another way to look at it is to imagine that a process incremented a
sempahore 560 times, decrements 100, increments, 50, and decrements
70.  Should the OS know to knock off 440 on the semaphore when the
process exits?  What happens if, at the point of abnormal termination,
the semaphore is zero because the other processes snarfed all the
counts?  Should the OS make the value -460?

> - If above is not true, is there any other mechanism to handle "Abandonment
> Issue" without relying on
>    some sort of process monitoring service etc..

A good solution to this problem is C++ exception handling.  Structure
your code so that if a hard exit occurs, the semaphore objects
automatically adjust reference count as necessary.

> - Is there any way to get the current available count without
> acquire/release on a semaphore?

Dunno.  Your best bet is probabably to ask one of the kernel people.

-John-


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.