Mutexes and Semaphores

First Published Tuesday, 29th September 2009 07:53 am from Real-Time Innovations (RTI) : Rick Warren

The opinions expressed by this blogger and those providing comments are theirs alone, this does not reflect the opinion of Automated Trader or any employee thereof. Automated Trader is not responsible for the accuracy of any of the information supplied by this article.


This post doesn't

contain any new information or clever opinions. It simply points

out a few articles published elsewhere that this humble author

suspects his readers will find relevant. (Members of the href="http://www.linkedin.com/groups?home=&gid=37565&trk=anet_ug_hm">Embedded

group on href="http://www.linkedin.com/">LinkedIn may have

seen some of these articles already, but they have relevance to

any multi-threaded system, embedded or not.)

Many developers suffer from confusion with respect to

the differences between mutexes and semaphores. Michael Barr of

Netrino

provides solid information in his article href="http://www.netrino.com/node/202">Mutexes and

Semaphores Demystified. My summary: mutexes

protect shared resources by enforcing mutual exclusion;

semaphores should be used for signaling across

tasks.

Niall Cooling

of Feabhas

provides a longer discussion in two parts:

  1. href="http://www.feabhas.com/blog/2009/09/mutex-vs-semaphores-part-1-semaphores.html">Mutex

    vs. Semaphores - Part 1: Semaphores

  2. href="http://www.feabhas.com/blog/2009/09/mutex-vs-semaphores-part-2-mutex.html">Mutex

    vs. Semaphores - Part 2: The Mutex

Cooling focuses especially on the problems

that arise when developers use semaphores where they should

rather use mutexes. In particular, he discusses accidental lock

release, various causes of deadlock, and priority inversion. (The

latter is of special interest to developers of real-time

software.)

Although semaphores and mutexes are

critical concurrency-control structures, the APIs to use them

unfortunately differ from platform to platform with respect to

both form and function. At the end of his Part 2, Cooling briefly

summarizes some of the differences between the semaphore and

mutex APIs of several operating systems. This section will be of

interest to anyone developing systems that will be ported across

very different platforms. Chris Simmonds goes into more depth,

with respect to Linux in particular, in his article href="http://www.embedded-linux.co.uk/tutorial/mutex_mutandis">Mutex

mutandis: understanding mutex types and

attributes posted on href="http://www.embedded-linux.co.uk/">The Inner

Penguin.



href="http://feeds.wordpress.com/1.0/gocomments/rtidds.wordpress.com/183/"> alt="" border="0"

src="http://feeds.wordpress.com/1.0/comments/rtidds.wordpress.com/183/"

/>

href="http://feeds.wordpress.com/1.0/godelicious/rtidds.wordpress.com/183/"> alt="" border="0"

src="http://feeds.wordpress.com/1.0/delicious/rtidds.wordpress.com/183/"

/>

href="http://feeds.wordpress.com/1.0/gostumble/rtidds.wordpress.com/183/"> alt="" border="0"

src="http://feeds.wordpress.com/1.0/stumble/rtidds.wordpress.com/183/"

/>

href="http://feeds.wordpress.com/1.0/godigg/rtidds.wordpress.com/183/"> alt="" border="0"

src="http://feeds.wordpress.com/1.0/digg/rtidds.wordpress.com/183/"

/>

href="http://feeds.wordpress.com/1.0/goreddit/rtidds.wordpress.com/183/"> alt="" border="0"

src="http://feeds.wordpress.com/1.0/reddit/rtidds.wordpress.com/183/"

/>

src="http://stats.wordpress.com/b.gif?host=blogs.rti.com&blog=7350090&post=183&subd=rtidds&ref=&feed=1"

/>

  • Copyright © Automated Trader Ltd 2013 - The Gateway to Algorithmic and Automated Trading

click here to return to the top of the page