From: Johannes Sixt <j.sixt@viscovery.net>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: msysgit@googlegroups.com, git@vger.kernel.org,
johannes.schindelin@gmx.de
Subject: Re: [PATCH/RFC] mingw: implement PTHREAD_MUTEX_INITIALIZER
Date: Tue, 25 Oct 2011 17:28:20 +0200 [thread overview]
Message-ID: <4EA6D594.90402@viscovery.net> (raw)
In-Reply-To: <1319554509-6532-1-git-send-email-kusmabite@gmail.com>
Am 10/25/2011 16:55, schrieb Erik Faye-Lund:
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> + if (mutex->autoinit) {
> + if (InterlockedCompareExchange(&mutex->autoinit, -1, 1) != -1) {
> + pthread_mutex_init(mutex, NULL);
> + mutex->autoinit = 0;
> + } else
> + while (mutex->autoinit != 0)
> + ; /* wait for other thread */
> + }
The double-checked locking idiom. Very suspicious. Can you explain why it
works in this case? Why are no Interlocked functions needed for the other
accesses of autoinit? ("It is volatile" is the wrong answer to this last
question, BTW.)
-- Hannes
next prev parent reply other threads:[~2011-10-25 15:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-25 14:55 [PATCH/RFC] mingw: implement PTHREAD_MUTEX_INITIALIZER Erik Faye-Lund
2011-10-25 15:28 ` Johannes Sixt [this message]
2011-10-25 15:42 ` Erik Faye-Lund
2011-10-25 20:07 ` [msysGit] " Johannes Sixt
2011-10-25 20:51 ` Erik Faye-Lund
2011-10-25 21:13 ` Johannes Sixt
2011-10-26 3:44 ` Kyle Moffett
2011-10-26 13:16 ` Erik Faye-Lund
2011-10-27 23:00 ` Atsushi Nakagawa
2011-10-27 23:20 ` Kyle Moffett
2011-10-28 18:35 ` Atsushi Nakagawa
2011-10-26 3:05 ` Atsushi Nakagawa
2011-10-26 13:08 ` [msysGit] " Erik Faye-Lund
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=4EA6D594.90402@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=kusmabite@gmail.com \
--cc=msysgit@googlegroups.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 NNTP newsgroup(s).