Semaphore support?

D

dln

I can't seem to find a Semaphore class in the .Net framework. Does C#
provide any blocking container objects that will block a thread trying to
extract an element from an empty queue or does the .Net framework provide a
Semaphore object of some type? I've noticed a post to the urls
http://www.codeproject.com/csharp/BoundedBlockingQueue.asp and
http://www.codeproject.com/csharp/DijkstraCountingSemaphore.asp, which will
work if necessary, but I'm more interested in native framework support if
possible.

Thanks.
 
J

Jon Skeet [C# MVP]

dln said:
I can't seem to find a Semaphore class in the .Net framework. Does C#
provide any blocking container objects that will block a thread trying to
extract an element from an empty queue or does the .Net framework provide a
Semaphore object of some type? I've noticed a post to the urls
http://www.codeproject.com/csharp/BoundedBlockingQueue.asp and
http://www.codeproject.com/csharp/DijkstraCountingSemaphore.asp, which will
work if necessary, but I'm more interested in native framework support if
possible.

No, there's no native framework support in 1.0/1.1, although there will
be in 2.0.
 
N

Nicholas Paldino [.NET/C# MVP]

dln,

In .NET 1.1, there is no Semaphore class. You would have to call the
CreateSemaphore API function (through the P/Invoke layer) and work with
that.

In .NET 2.0, there is a Semaphore class that you can use which gives you
the semantics that you want.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top