git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [msysGit] Re: [PATCH/RFC] mingw: implement PTHREAD_MUTEX_INITIALIZER

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 25, 2011, 21:13 UTC
Message-ID
<4EA7267E.1080103@kdbg.org>
In-Reply-To
<CABPQNSY6-j7iNagsJc3WKVZ94=yZHdfBswA-v0XY7vH+RxyjYQ@mail.gmail.com>
Am 25.10.2011 22:51, schrieb Erik Faye-Lund:
Show 13 quoted lines
> On Tue, Oct 25, 2011 at 10:07 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>> HOWEVER, when it continues, there is NO [*] guarantee that it will also
>> see the values that InitializeCriticalSection() has written, because
>> there were no memory barriers involved. When it continues, there is a
>> chance that it calls EnterCriticalSection() with uninitialized values!
>>
> 
> Thanks for pointing this out, I completely forgot about write re-ordering.
> 
> This is indeed a problem. So, shouldn't replacing "mutex->autoinit =
> 0;" with "InterlockedExchange(&mutex->autoinit, 0)" solve the problem?
> InterlockedExchange generates a full memory barrier:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms683590(v=vs.85).aspx
That should do it.
Show 6 quoted lines
>> [*] If you compile this code with MSVC >= 2005, "No guarantee" is not
>> true, it's exactly the opposite because Microsoft extended the meaning
>> of 'volatile' to imply a memory barriere.
> 
> Do you have a source for this? I'm not saying it isn't true, I just
> never heard of this, and would like to read up on it :)
http://msdn.microsoft.com/en-us/library/ms686355%28VS.85%29.aspx
-- Hannes
Previous: Erik Faye-LundNext: Kyle Moffett
Message 6 of 13 in “mingw: implement PTHREAD_MUTEX_INITIALIZER”
  1. mingw: implement PTHREAD_MUTEX_INITIALIZERErik Faye-Lund, Oct 25, 2011
  2. Johannes SixtOct 25, 2011
  3. Erik Faye-LundOct 25, 2011
  4. Johannes SixtOct 25, 2011
  5. Erik Faye-LundOct 25, 2011
  6. Johannes SixtOct 25, 2011
  7. Kyle MoffettOct 26, 2011
  8. Erik Faye-LundOct 26, 2011
  9. Atsushi NakagawaOct 27, 2011
  10. Kyle MoffettOct 27, 2011
  11. Atsushi NakagawaOct 28, 2011
  12. Atsushi NakagawaOct 26, 2011
  13. Erik Faye-LundOct 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.