Working with Semaphores

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I cannot find an object for managing access to semaphores within the .net framework (I have found the Mutex and unamed Events) but nothing for semaphores or named events....

can someone point me in the right direction, or are they not supported under the dot net framework

Myles.
 
MDFS said:
I cannot find an object for managing access to semaphores within the
.net framework (I have found the Mutex and unamed Events) but nothing
for semaphores or named events.....

can someone point me in the right direction, or are they not supported
under the dot net framework?

I don't know about named events, but semaphores can certainly be
constructed from Monitors.
 
Hi John
Thanks for that,
Ahh I think a bit of background is required... I'm a development engineer with significant experience especially with Win32. I'm trying to use .net without stepping back into the OS (lets face it, if you don't have to then don't do it!

So by named events I mean an event which is given a name so that it can be accessed by co-operating processes, basically I'm looking for the .Net management class for Win32 Events ala:
HANDLE CreateEvent
LPSECURITY_ATTRIBUTES lpEventAttributes
BOOL bManualReset
BOOL bInitialState
LPCTSTR lpNam
)

With regard to the monitor class I can see how you can "construct" a semaphore, but again what I should have asked was is there a .net class that would manage OS based calls ala
HANDLE CreateSemaphore
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes
LONG lInitialCount
LONG lMaximumCount
LPCTSTR lpNam
)

I know how to create and call these function directly from .net languages but what I want to know is there a management class that wrapps up these functions in the same way that Mutex does it for the Mutex calls, that way I should just be able to create the objects and use them...

Does this make sense

Again sorry for not expressing myself correctly the first time
Regards
Myle
 
MDFS said:
Ahh I think a bit of background is required... I'm a development
engineer with significant experience especially with Win32. I'm trying
to use .net without stepping back into the OS (lets face it, if you
don't have to then don't do it!)

So by named events I mean an event which is given a name so that it
can be accessed by co-operating processes, basically I'm looking for
the .Net management class for Win32 Events ala:

<snip>

No, I don't believe there's anything which wraps the existing Win32
events/semaphores. You could write one yourself, of course, so that it
called P/Invoke appropriately.
 
William Stacey said:
For some reason the semaphore was not included under
System.Threading.WaitHandle. It may be because CE does not support them.

I shouldn't think so - various other bits of threading are in the full
framework but not the compact framework (even simple things like
wait/pulse on monitors).

<snip other interesting stuff>
 
Interesting.... Just did a quick search in MSDN, CE 3.0 supports semaphores but there is no references for .Net....
So have MS removed it and not explicitly stated that they have or is it still sitting in the background and not mentioned because the .Net framework doesn't support it

Ahh well, I'm just going to call the OS functions as I need them.... Pitt

Thanks to you both

Regards
Myles
 
On locking and .net and win32. I did run into an issue once (can't remember
exactly to repro) involving "lock" and calling native mutex in same program.
They worked, but caused a deadlock on my Circular Queue for some reason.
Replacing mutex with the native .net mutex, did not show the problem.
Replace with win32 mutex, problem back. When I used "all" win32 apis for
mutex and sem, everthing worked. I don't know if this is true, but I
figured it may have something to do with how they handle locking contexts
and mem barriers. Point is, not sure I would mix win32 and .net sync
objects in same method without a lot of testing with as many threads as you
need. I could probably (with some work), reproduce this if anyone is
interested.

--
William Stacey, MVP

MDFS said:
Interesting.... Just did a quick search in MSDN, CE 3.0 supports
semaphores but there is no references for .Net.....
So have MS removed it and not explicitly stated that they have or is it
still sitting in the background and not mentioned because the .Net framework
doesn't support it?
 
Back
Top