From: "Bert Wesarg" <bert.wesarg@googlemail.com>
To: "Sebastian Andrzej Siewior" <sebastian@breakpoint.cc>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Thomas Gleixner" <tglx@linutronix.de>,
"Ulrich Drepper" <drepper@redhat.com>
Subject: Re: [PATCH v2] add man-page for pthread_mutexattr_setrobust_np()
Date: Mon, 22 Dec 2008 12:05:31 +0100 [thread overview]
Message-ID: <36ca99e90812220305p1ed3d5aehe46025eb8fae6158@mail.gmail.com> (raw)
In-Reply-To: <20081222103953.GB15345@Chamillionaire.breakpoint.cc>
>>> +static int create_new_lock(void)
>>> +{
>>> + int fd;
>>> + pthread_mutex_t cmutex = PTHREAD_MUTEX_INITIALIZER;
>>> + pthread_mutexattr_t attr;
>>> + int ret;
>>> +
>>> + pthread_mutexattr_init(&attr);
>>> + pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP);
>>> + pthread_mutex_init(&cmutex, &attr);
>>> +
>>> + fd = open(lock_name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR |
>>> + S_IRGRP | S_IWGRP);
>>> + if (fd < 0)
>>> + return fd;
>>> +
>>> + ret = write(fd, &cmutex, sizeof(cmutex));
>>I think its undefined behavior if you copy a struct pthread_mutex. You
>>should use mmap here too.
> Why should be this undefined? Is there something special about this
> struct? And why should this behave different with mmap() ?
If you would use mmap, you would initialize the mutex inside the
mmaped area, i.e. directly in the file.
To the copying:
Short answer: http://www.lambdacs.com/cpt/FAQ.html#Q15
Slightly longer:
pthread_mutex_t m1, m2;
pthread_mutex_init(&m1, NULL);
pthread_mutex_lock(&m1);
m2 = m1;
pthread_mutex_unlock(&m2);
How can you be sure, that you have unlocked m1 here?
Yes, you throw away the cmutex after returning from the function and
the copy inside the file is the only one left. I still think such code
should not be in a documentation.
Bert
>
> Sebastian
>
prev parent reply other threads:[~2008-12-22 11:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-01 21:34 man page for robust mutexes Sebastian Andrzej Siewior
2008-12-07 16:44 ` Michael Kerrisk
2008-12-21 20:59 ` [PATCH v2] add man-page for pthread_mutexattr_setrobust_np() Sebastian Andrzej Siewior
2008-12-22 7:32 ` Bert Wesarg
2008-12-22 10:39 ` Sebastian Andrzej Siewior
2008-12-22 11:05 ` Bert Wesarg [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=36ca99e90812220305p1ed3d5aehe46025eb8fae6158@mail.gmail.com \
--to=bert.wesarg@googlemail.com \
--cc=drepper@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=sebastian@breakpoint.cc \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®