What is the C# Semaphore equivalent?

  • Thread starter Thread starter Nadav
  • Start date Start date
N

Nadav

What is the C# Semaphore equivalent? I can't find any... is there an
equivalent????

Nadav
 
Nadav said:
What is the C# Semaphore equivalent? I can't find any... is there an
equivalent????

You can fairly easily build a semaphore out of monitors.
 
Well, That's rights, but I don't need to imitate the semaphore functionality
I need to be sure that the CLR uses the exact implementation used by the
Win32 Semaphore logic, e.g. any thread can decrease the reference count of a
semaphore, the owning thread WILL BLOCK on repeating acquisitions of the
semaphore ( in contrast to mutex ), ...

Does the Monitor object supports the features just mentioned?

Nadav.
 
Nadav said:
Well, That's rights, but I don't need to imitate the semaphore functionality
I need to be sure that the CLR uses the exact implementation used by the
Win32 Semaphore logic, e.g. any thread can decrease the reference count of a
semaphore, the owning thread WILL BLOCK on repeating acquisitions of the
semaphore ( in contrast to mutex ), ...

Does the Monitor object supports the features just mentioned?

It does if you want it to - the semaphore will act however you design
it to act, but basically monitor gives you enough building blocks to
achieve it.
 
Nadav,
As Jon stated, you can build a Semaphore using Monitor & some of your own
code.

If you want a Win32 Semaphore, you can use P/Invoke and use a Win32
Semaphore. If I went the P/Invoke method I would consider deriving from
System.Threading.WaitHandle to allow my Semaphore to "place nice" with the
rest of the framework.

Hope this helps
Jay

Nadav said:
Well, That's rights, but I don't need to imitate the semaphore functionality
I need to be sure that the CLR uses the exact implementation used by the
Win32 Semaphore logic, e.g. any thread can decrease the reference count of a
semaphore, the owning thread WILL BLOCK on repeating acquisitions of the
semaphore ( in contrast to mutex ), ...

Does the Monitor object supports the features just mentioned?

Nadav.
 
Well,
1. Using Monitor may resolve the problem But I am disterbed by the fact that
the semaphore logic would have to ran in the application level and not in
the kernel ( as Win32 semaphore logic does ).
2. Using the Win32 semaphore raises some questions: Does Micrsoft is
planning to stop supporting the Win32 API layer in future OS versions? Does
microsoft is planning to add the semaphore functionality in future versions
of the CLR?

Nadav.

Jay B. Harlow said:
Nadav,
As Jon stated, you can build a Semaphore using Monitor & some of your own
code.

If you want a Win32 Semaphore, you can use P/Invoke and use a Win32
Semaphore. If I went the P/Invoke method I would consider deriving from
System.Threading.WaitHandle to allow my Semaphore to "place nice" with the
rest of the framework.

Hope this helps
Jay

Nadav said:
Well, That's rights, but I don't need to imitate the semaphore functionality
I need to be sure that the CLR uses the exact implementation used by the
Win32 Semaphore logic, e.g. any thread can decrease the reference count
of
 
Nadav,
I cannot specifically answer either of your questions, however I have to add
a question to your two questions:

Should Microsoft tie the .NET framework specifically to Win32?

Also as I stated your #2 is easily answered, by using P/Invoke.

Hope this helps
Jay
 
I am not going to answer the semaphore Question!
I don't know if the Microsoft should tie .net to win32 or not! but there are
a lot of very rich feature that exist in the win32 platform with yet no
equiv. in .net which I personally like to use and even there is no
foundation classes in C# like in VC++ so I should import every function I
need by hand! I can tolerate the "platform specific" warning or "will not be
supported in the future or will be replaced with introduction of new
features" for every single line of code because I am not going to leave that
75% of Windows users and write code for the platforms that .net MAY get
implemented on them.
(sure i'd love the .net to expand on the new platforms)
but why do I use .net? because it has a lot of very great feature in itself
too that I don't want to lose and write pure C code in year 2004!

I don't know about the qu
 
Back
Top