From: Atsushi Nakagawa <atnak@chejz.com>
To: msysgit@googlegroups.com
Cc: git@vger.kernel.org, johannes.schindelin@gmx.de, j.sixt@viscovery.net
Subject: Re: [PATCH/RFC] mingw: implement PTHREAD_MUTEX_INITIALIZER
Date: Tue, 25 Oct 2011 20:05:19 -0700 (PDT) [thread overview]
Message-ID: <16520370.401.1319598319120.JavaMail.geo-discussion-forums@prms22> (raw)
In-Reply-To: <1319554509-6532-1-git-send-email-kusmabite@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1344 bytes --]
On Oct 25, 11:55 pm, Erik Faye-Lund <kusmab...@gmail.com> wrote:
> [...]
> +int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t
*attr)
> +{
> + InitializeCriticalSection(&mutex->cs);
> + mutex->autoinit = 0;
> + return 0;
> +}
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> + if (mutex->autoinit) {
> + if (InterlockedCompareExchange(&mutex->autoinit, -1, 1)
!= -1) {
I'm making the assumption that mutex->autoinit starts off as 1 before
things get multi-threaded..
I've only looked at what's in the patch so I could be missing vital
context.. Anyways, is there a reason why you made this
"InterlockedCompareExchange(..., -1, 1) != -1" and not
"InterlockedCompareExchange(..., -1, 1) == 1"?
It looks to me the former adds a race condition after "if (mutex->autoinit)
{". e.g. A second thread could reinitialize mutex->cs after the first
thread has already entered EnterCriticalSection(...).
> + pthread_mutex_init(mutex, NULL);
> + mutex->autoinit = 0;
> + } else
> + while (mutex->autoinit != 0)
> + ; /* wait for other thread */
> + }
> +
> + EnterCriticalSection(&mutex->cs);
> + return 0;
> +}
> [...]
--
Atsushi Nakagawa
[-- Attachment #2: Type: text/html, Size: 2272 bytes --]
next prev parent reply other threads:[~2011-10-26 8:05 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
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 [this message]
2011-10-26 13:08 ` 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=16520370.401.1319598319120.JavaMail.geo-discussion-forums@prms22 \
--to=atnak@chejz.com \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=johannes.schindelin@gmx.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.