From: Ross Johnson <rpj@ise.canberra.edu.au>
To: Rotem Shacham <rotem.shacham@bluesoft-inc.com>
Cc: Posix Mailing list <pthreads-win32@sourceware.cygnus.com>
Subject: Re: dmutex
Date: Tue, 07 Aug 2001 20:26:00 -0000 [thread overview]
Message-ID: <3B70B14C.EB5C973D@ise.canberra.edu.au> (raw)
In-Reply-To: <MEEGJNAGDGABKCMJEPIHEEKLCAAA.rotem.shacham@bluesoft-inc.com>
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
prev parent reply other threads:[~2001-08-07 20:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-07 9:18 dmutex Rotem Shacham
2001-08-07 20:26 ` Ross Johnson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3B70B14C.EB5C973D@ise.canberra.edu.au \
--to=rpj@ise.canberra.edu.au \
--cc=pthreads-win32@sourceware.cygnus.com \
--cc=rotem.shacham@bluesoft-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).