Who gets the Mutex?
-
Hi I have a threaded app which can have many threads running (number not known until runtime). Each thread needs to use shared resource so I lock with WaitOnSingleObject and pass a handle to a mutex. The handle is a global variable assigned with CreateMutex so all threads have access to it and this method works fine. Whilst one thread has access to the shared resource, other threads are sitting INFINITE at the WaitOnSingleObject. Do these threads get access on a first come first served basis or is there a possibility that a thread could constantly be shoved to the back of the queue by others threads pushing in? Which leads me onto a second question - can you give a thread higher priority (easily) ? Cheers Angel1058 ********************************************* The sooner you fall behind, the longer you have to catch up.
-
Hi I have a threaded app which can have many threads running (number not known until runtime). Each thread needs to use shared resource so I lock with WaitOnSingleObject and pass a handle to a mutex. The handle is a global variable assigned with CreateMutex so all threads have access to it and this method works fine. Whilst one thread has access to the shared resource, other threads are sitting INFINITE at the WaitOnSingleObject. Do these threads get access on a first come first served basis or is there a possibility that a thread could constantly be shoved to the back of the queue by others threads pushing in? Which leads me onto a second question - can you give a thread higher priority (easily) ? Cheers Angel1058 ********************************************* The sooner you fall behind, the longer you have to catch up.
The queue to get access to the mutex is on a first-in, first-out basis. So the first thread to wait on the mutex will get access to it when it is released, regardless of thread priority. Mike
-
Hi I have a threaded app which can have many threads running (number not known until runtime). Each thread needs to use shared resource so I lock with WaitOnSingleObject and pass a handle to a mutex. The handle is a global variable assigned with CreateMutex so all threads have access to it and this method works fine. Whilst one thread has access to the shared resource, other threads are sitting INFINITE at the WaitOnSingleObject. Do these threads get access on a first come first served basis or is there a possibility that a thread could constantly be shoved to the back of the queue by others threads pushing in? Which leads me onto a second question - can you give a thread higher priority (easily) ? Cheers Angel1058 ********************************************* The sooner you fall behind, the longer you have to catch up.
The scheduler makes no promises, except that it will be "fair to all threads" (which is enough for your case). Also, there are substantial differences in the scheduler implementation between 9x and NT platforms.
we are here to help each other get through this thing, whatever it is Vonnegut jr.
boost your code || Fold With Us! || sighist | doxygen