• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom data formatter for pthread_mutex_t?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom data formatter for pthread_mutex_t?


  • Subject: Re: Custom data formatter for pthread_mutex_t?
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 16 Aug 2007 20:15:56 +0100

On 15 Aug 2007, at 15:05, Cem Karan wrote:

On Tue, 14 Aug 2007 22:47:13 +0100, Peter Mulholland wrote:

What you're suggesting would be useful though... in a function would
be even more useful.. like pthread_mutex_state().

Thank you both. Peter, I agree with you that as a function, this would be extremely useful. In a way, I'm kind of surprised that the POSIX spec doesn't have it. Dave, you're right that I can probably download the source and write up my own pthread_mutex_state ().

You don't need the source for that:

typedef enum { LOCKED = 1, UNLOCKED = 0, INVALID = -1 } mutex_state_t;

  mutex_state_t
  pthread_mutex_state (pthread_mutex_t *mutex)
  {
    int ret = pthread_mutex_trylock (mutex);

    if (ret == 0) {
      pthread_mutex_unlock (mutex);
      return UNLOCKED;
    }

    if (ret == EBUSY)
      return LOCKED;

    return INVALID;
  }

Obviously it's not perfect, since it will lock and unlock the mutex to do its test (sometimes, anyway). You might be able to come up with a better solution by getting the code from Darwin, though from what I remember it's all based on Mach primitives under the covers anyway, so you'd need some way to get *their* state in order to do much better.

Kind regards,

Alastair.

--
http://alastairs-place.net




_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • RE: Custom data formatter for pthread_mutex_t?
      • From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>
References: 
 >Re: Custom data formatter for pthread_mutex_t? (From: Cem Karan <email@hidden>)

  • Prev by Date: Re: How do start from scratch?
  • Next by Date: RE: Custom data formatter for pthread_mutex_t?
  • Previous by thread: Re: Custom data formatter for pthread_mutex_t?
  • Next by thread: RE: Custom data formatter for pthread_mutex_t?
  • Index(es):
    • Date
    • Thread