Jump to page: 1 2
Thread overview
[Issue 14617] PTHREAD_MUTEX_INITIALIZER does not work on OSX
May 23, 2015
Martin Nowak
May 23, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu

--- Comment #1 from Martin Nowak <code@dawg.eu> ---
According to the headers, the initializer should be {0x32AAABA7}. http://www.opensource.apple.com/source/Libc/Libc-167/pthreads.subproj/pthread.h

--
May 23, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
According to testing:

Stevens-MacBook-Pro:testd steves$ cat pthreadm.cpp
#include <pthread.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
    unsigned char *b = (unsigned char *)&x;
    unsigned char *e = (unsigned char *)((&x) + 1);
    while(b != e)
        printf("%02x ", (int)*b++);
    printf("\n");
}
Stevens-MacBook-Pro:testd steves$ ./pthreadm
a7 ab aa 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00


So that jives with Martin's research. I'll see about a PR.

--
May 23, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
A neat advantage over C is that we can define the .init value so we don't need such an initializer. In fact, core.posix.pthread defines PTHREAD_MUTEX_INITIALIZER as pthread_mutex_t.init.

However, there is an issue, because core/sys/posix/sys/types.d is not included in the build. So if I define a new init, it won't be found (tried it).

I also tried updating the PTHREAD_MUTEX_INITIALIZER in pthread.d, and that also is not found. So we need some Makefile updates in order to fix this. And I'm not sure we want to do that. Thoughts?

--
May 23, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #4 from Andrei Alexandrescu <andrei@erdani.com> ---
Thanks for all this, folks! Steve, can't you just insert the proper defaults where the struct is defined? I.e. we have in src/core/sys/posix/sys/types.d the following definition at line 594:

    struct pthread_mutex_t
    {
        c_long                              __sig;
        byte[__PTHREAD_MUTEX_SIZE__]        __opaque;
    }

Changing it to the following makes at least my tests pass:

    struct pthread_mutex_t
    {
        c_long                              __sig = 0x32AAABA7;
        byte[__PTHREAD_MUTEX_SIZE__]        __opaque;
    }

--
May 24, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Andrei, that's exactly what I did.

I just realized, I messed up and left that initializer in the types.d file, when I tried doing it in the pthread.d file.

Fixing that, it does work. So we have a potential fix (not the preferred) of fixing only PTHREAD_MUTEXT_INITIALIZER. I'll push the one with setting the init value, and you can see whether it's easy to fix the Makefile.

Maybe I did something wrong with my testing...

--
May 24, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> ---
PR: https://github.com/D-Programming-Language/druntime/pull/1285

--
May 25, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #7 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Yep, still fails in the autotester. What do we want to do?

a) just fix pthread.d so PTHREAD_MUTEX_INITIALIZER is proper, but
pthread_mutex_t.init is not
b) fix the Makefile so it properly includes types.d in the (unittest?) build.

Whatever we do, we should spend the time to figure out all the initializers on all systems, so code will be portable.

--
May 25, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #8 from Andrei Alexandrescu <andrei@erdani.com> ---
I now understand. Let's leave types.d be code-free for now (in fact it could be renamed to types.di) and only fix PTHREAD_MUTEX_INITIALIZER at least for now.

--
May 25, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #9 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/ab78a534dc017efecbe86f79f5d4559b85ef8619
fix issue 14617 - Define correct values for PTHREAD_MUTEX_INITIALIZER and
PTHREAD_ONCE_INIT.

https://github.com/D-Programming-Language/druntime/commit/19f3f0db648b6361248e2c53e00fcb3794c2521b Merge pull request #1285 from schveiguy/pthreadmutexosx

Fix issue 14617 - PTHREAD_MUTEX_INITIALIZER does not work on OSX

--
June 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14617

--- Comment #10 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/ab78a534dc017efecbe86f79f5d4559b85ef8619
fix issue 14617 - Define correct values for PTHREAD_MUTEX_INITIALIZER and
PTHREAD_ONCE_INIT.

https://github.com/D-Programming-Language/druntime/commit/19f3f0db648b6361248e2c53e00fcb3794c2521b Merge pull request #1285 from schveiguy/pthreadmutexosx

--
« First   ‹ Prev
1 2