public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* dmutex
@ 2001-08-07  9:18 Rotem Shacham
  2001-08-07 20:26 ` dmutex Ross Johnson
  0 siblings, 1 reply; 2+ messages in thread
From: Rotem Shacham @ 2001-08-07  9:18 UTC (permalink / raw)
  To: Posix Mailing list

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

Hi, 
Saw a reference in an article about pthreads to a dmutex (debug mutex) that
can (for debug reasons) keep track of its owning thread.

Is the above implemented ? 

Thanks,

[-- Attachment #2: winmail.dat --]
[-- Type: application/vnd.ms-tnef, Size: 1812 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dmutex
  2001-08-07  9:18 dmutex Rotem Shacham
@ 2001-08-07 20:26 ` Ross Johnson
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Johnson @ 2001-08-07 20:26 UTC (permalink / raw)
  To: Rotem Shacham; +Cc: Posix Mailing list

Rotem Shacham wrote:
> 
> Hi,
> Saw a reference in an article about pthreads to a dmutex (debug mutex) that
> can (for debug reasons) keep track of its owning thread.
> 
> Is the above implemented ?
> 

You can set the mutex "type" attribute to PTHREAD_MUTEX_ERRORCHECK via
pthread_mutexattr_settype(). Then, once you're satisfied that your
program is working correctly you can switch to using the default
type or PTHREAD_MUTEX_NORMAL specifically, in order to get faster
mutexes.

pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type)

     /*
      * ------------------------------------------------------
      *
      * DOCPUBLIC
      * The pthread_mutexattr_settype() and
      * pthread_mutexattr_gettype() functions  respectively set and
      * get the mutex type  attribute. This attribute is set in  the
      * type parameter to these functions.
      *
      * PARAMETERS
      *      attr
      *              pointer to an instance of pthread_mutexattr_t
      *
      *      type
      *              must be one of:
      *
      *                      PTHREAD_MUTEX_NORMAL
      *
      *                      PTHREAD_MUTEX_ERRORCHECK
      *
      *                      PTHREAD_MUTEX_RECURSIVE
      *
      *
      * DESCRIPTION
      * The pthread_mutexattr_settype() and
      * pthread_mutexattr_gettype() functions  respectively set and
      * get the mutex type  attribute. This attribute is set in  the
      * type  parameter to these functions. The default value of the
      * type  attribute is  PTHREAD_MUTEX_DEFAULT.
      * 
      * The type of mutex is contained in the type  attribute of the
      * mutex attributes. Valid mutex types include:
      *
      * PTHREAD_MUTEX_NORMAL
      *          This type of mutex does  not  detect  deadlock.  A
      *          thread  attempting  to  relock  this mutex without
      *          first unlocking it will  deadlock.  Attempting  to
      *          unlock  a  mutex  locked  by  a  different  thread
      *          results  in  undefined  behavior.  Attempting   to
      *          unlock  an  unlocked  mutex  results  in undefined
      *          behavior.
      * 
      * PTHREAD_MUTEX_ERRORCHECK
      *          This type of  mutex  provides  error  checking.  A
      *          thread  attempting  to  relock  this mutex without
      *          first unlocking it will return with  an  error.  A
      *          thread  attempting to unlock a mutex which another
      *          thread has locked will return  with  an  error.  A
      *          thread attempting to unlock an unlocked mutex will
      *          return with an error.
      *
      * PTHREAD_MUTEX_DEFAULT
      *          Same as PTHREAD_MUTEX_NORMAL.
      * 
      * PTHREAD_MUTEX_RECURSIVE
      *          A thread attempting to relock this  mutex  without
      *          first  unlocking  it  will  succeed in locking the
      *          mutex. The relocking deadlock which can occur with
      *          mutexes of type  PTHREAD_MUTEX_NORMAL cannot occur
      *          with this type of mutex. Multiple  locks  of  this
      *          mutex  require  the  same  number  of  unlocks  to
      *          release  the  mutex  before  another  thread   can
      *          acquire the mutex. A thread attempting to unlock a
      *          mutex which another thread has locked will  return
      *          with  an  error. A thread attempting to  unlock an
      *          unlocked mutex will return  with  an  error.  This
      *          type  of mutex is only supported for mutexes whose
      *          process        shared         attribute         is
      *          PTHREAD_PROCESS_PRIVATE.
      *
      * RESULTS
      *              0               successfully set attribute,
      *              EINVAL          'attr' or 'type' is invalid,
      *
      */

Ross

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-07 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-07  9:18 dmutex Rotem Shacham
2001-08-07 20:26 ` dmutex Ross Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).