Thread: Mutex question

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    13

    Mutex question

    Is it possible to tell which thread has a pthread mutex lock at a given moment?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It might be, if you told us which implementation you're working with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    13
    Quote Originally Posted by Salem View Post
    It might be, if you told us which implementation you're working with.
    Sorry, I thought the point of posix threads is that they work the same.

    It's on Mac OSX 10.4.10. Is that what you needed?

    Thanks

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    There's nothing in standard posix for doing that (that I could find). But your implementation of pthreads could have non-stadard "features" for doing such things.

    You could create your own mutex lock "object wrapper" and save off the owning thread yourself using pthread_self().

    gg

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Just curious to know, how many thread are there in your implementation and how many of them uses the Critical part.

    ssharish
    Last edited by ssharish2005; 09-17-2007 at 12:22 PM.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by laertius View Post
    Is it possible to tell which thread has a pthread mutex lock at a given moment?
    If your implementation of pthreads supports recursive mutexes, then there is probably a way to get it. A recursive mutex can be repeatedly locked by the thread which holds it -- this implies that the identity of this thread is stored somewhere. Whether you can actually gain access to this identity, I don't know. The answer is undoubtedly going to involve poking in the pthreads internals.

    Otherwise, just invent your own mutex structure to wrap the mutex in question, and keep the identity of the locking thread up to date along with the mutex.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. Semaphores Question
    By ch4 in forum C Programming
    Replies: 2
    Last Post: 01-02-2009, 01:32 PM
  3. Quick mutex question
    By Thantos in forum Linux Programming
    Replies: 1
    Last Post: 02-21-2004, 07:10 PM
  4. Mutex - location of lock/unlock
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 08-14-2003, 12:28 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM