Mutex vs. Semaphore

This is a discussion on Mutex vs. Semaphore within the C++ Programming forums, part of the General Programming Boards category; What is the difference between mutex's and semaphore's ? From looking at descriptions of them in previous threads they seem ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    38

    Mutex vs. Semaphore

    What is the difference between mutex's and semaphore's ? From looking at descriptions of them in previous threads they seem to have extremly similar purposes?
    chris

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    With Win32 at least, the main difference is that a mutex is either owned or not. If the mutex is owned when a thread/process tries to acquire it, the thread will block.

    A semaphore has a counter. You can specify a number greater than 1. Thus if a thread tries to get the semaphore, (bumping the counter), and getting it will not exceed the maximum, the thread can continue. Several threads/processes can own the same semaphore at the same time.

    Thus a semaphore can be made to look like a mutex, but not the other way round. They have similar functionality otherwise.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-11-2007, 04:59 PM
  2. Semaphore Question
    By azamsharp1 in forum C Programming
    Replies: 4
    Last Post: 10-30-2005, 08:01 AM
  3. CreateSemaphore/ReleaseSemaphore
    By nrieger in forum Windows Programming
    Replies: 2
    Last Post: 08-03-2005, 06:57 AM
  4. semaphore or mutex
    By Micko in forum Windows Programming
    Replies: 2
    Last Post: 07-05-2004, 10:39 AM
  5. Producer-comsumer threads using semaphore mutex
    By Kaiya in forum C Programming
    Replies: 3
    Last Post: 04-29-2004, 08:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21