Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Who gets the Mutex?

Who gets the Mutex?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureslearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Malcolm Smart
    wrote on last edited by
    #1

    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.

    M P 2 Replies Last reply
    0
    • M Malcolm Smart

      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.

      M Offline
      M Offline
      Mike Beckerleg
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Malcolm Smart

        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.

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups