SDL Mutex locks - sorry had wrong subject,.. ignore : Re: Distributing a SDL Mac app

Hi all,

Just a quick question,…
Are mutex locks resolved in calling order ?

Scenario:

A thread has locked our mutex and is doing it’s thing. ( let’s call this thread 1 )
2 other threads ( let’s call this 2 and 3 in calling order ) also call the lock mutex for this task and thus have to wait untill our first thread is finished.
now… once’s thread 1 is finished is there a mechanism that makes sure thread 2 will be next or could it be either 2 or 3 dependant on polling or whatever.

GreeTz--------------------------------
| Dinand Vanvelzen, |
| Programmer, |

Software Engineering student

Hi all,

Just a quick question,…
Are mutex locks resolved in calling order ?

Scenario:

A thread has locked our mutex and is doing it’s thing. ( let’s call
this thread 1 )
2 other threads ( let’s call this 2 and 3 in calling order ) also call
the lock mutex for this task and thus have to wait untill our first
thread is finished.
now… once’s thread 1 is finished is there a mechanism that makes
sure thread 2 will be next or could it be either 2 or 3 dependant on
polling or whatever.

Depends on the type of mutex you are using. If it is a simple lock, then
when the lock is unlocked, all threads waiting on the lock wake up and
which ever one locks the lock gets it. No guarantee of order. If thread
2 and 3 are waiting on the lock, and thread 1 unlocks it, then either
thread 2 or 3 will try to lock it. But, their is no guarantee that
either one will lock it. Thread 1 is still running and will keep running
until it either exceeds its scheduling quanta or until it is blocked.
So, thread 1 could relock the mutex and lock 2 and 3 out again. Also, if
2 gets the lock, when it unlocks it 3 might get it, and might not. I’ve
seen people write code with three or more threads that access a critical
section controlled by a mutex where threads 2 and 3 never ran.

The only way you can make sure a thread runs is to ensure that it is the
only thread that CAN run.

		Bob PendletonOn Mon, 2003-05-05 at 04:54, Dinand Vanvelzen wrote:

GreeTz


| Dinand Vanvelzen, |
| Programmer, |

Software Engineering student


±----------------------------------+

  • Bob Pendleton: independent writer +
  • and programmer. +
  • email: Bob at Pendleton.com +
    ±----------------------------------+