Professional Web Applications Themes

pthread / UDP support on OS X? - Mac Programming

Hi all, I'm developing a multiplatform portable base services library, and I've come across some strange behaviour on Mac OS X 10.2. I'm using the sourceforge.net compile farm to test the library, and while the test suite completes successfully on all other platforms (including two that sf.net doesn't have), it runs into trouble on the Mac. What I'd like is for someone knowledgable to take a look at it and either help me fix my OS X bugs, or, tell me that OS X 10.2 is broken for the particular tests that fail and sourceforge should upgrade. There are at ...

  1. #1

    Default pthread / UDP support on OS X?

    Hi all,

    I'm developing a multiplatform portable base services library, and I've
    come across some strange behaviour on Mac OS X 10.2. I'm using the
    sourceforge.net compile farm to test the library, and while the test
    suite completes successfully on all other platforms (including two that
    sf.net doesn't have), it runs into trouble on the Mac.

    What I'd like is for someone knowledgable to take a look at it and
    either help me fix my OS X bugs, or, tell me that OS X 10.2 is broken
    for the particular tests that fail and sourceforge should upgrade.

    There are at least two separate issues, I think. The most severe one is
    that a counter variable that's being accessed from several threads (but
    with a mutex guarding it) manages to revert to a previous value, even
    though the only operation made on it is post-increment (and, no, it's
    not a wrap-around... see below.)

    The other issue is that when testing UDP, a random number of threads
    will fail to open a UDP port for sending, with no error message set by
    the OS.

    The project link is http://sourceforge.net/projects/portbase/
    To test, simply do the old ./configure && make check.

    Tested platforms that work fine:

    [x86] Windows 2000 (SP4 using Visual C++ 6.0)
    [x86] Windows 2000 (SP4 using MSYS/MinGW)
    [x86] Linux 2.4 (Debian 2.2)
    [x86] Linux 2.4 (Redhat 9.0)
    [x86] OpenBSD (3.4)
    [x86] FreeBSD (4.8)
    [x86] NetBSD (1.6.1)
    [AMD64] Linux 2.4 (SuSE 8 ES on AMD64 Opteron)
    [Alpha] Linux 2.2 (Debian 3.0)
    [Sparc - R220] Sun Solaris (9)

    On the [PPC - G4] MacOS X 10.2 SERVER Edition, the test suite threads
    part fails with some interesting messages, some of which seem to
    indicate that either there is a major flaw in the test logic, or that
    the OS X compiler is broken:

    base: OK [big-endian <01020304>, 32 bits]
    date: OK [2004-01-19: Mon, week 4, yearday 19. J=2453024 (leap)]
    dir: OK [454696 source bytes]
    string: OK
    string/map: OK [82% unique of 100000]
    string/uri: OK
    test/test_thread.c(138) : !"pbThreadDestroy() not working"
    test/test_thread.c(180) : counter >= last_counter [3981 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3971 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3961 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3951 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3941 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3931 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3921 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3911 < 3991]
    test/test_thread.c(180) : counter >= last_counter [3901 < 3991]
    test/test_thread.c(190) : counter == NUMTHREADS*COUNT_LIMIT [3891 !=
    4000]
    threads: 11 FAILED
    make: [check] Error 11 (ignored)
    net/address: OK ['ppc-osx2.cf.sourceforge.net' IPs: 10.8.5.41]
    net/tcp: OK [0% timeouts, 33033 messages]
    test/test_netudp.c(48) : (sock = pbNetUDPOpen( addr )) != NULL
    ... snip 33 identical lines ...
    test/test_netudp.c(48) : (sock = pbNetUDPOpen( addr )) != NULL
    net/udp: 35 FAILED [0% packet loss, 1500 messages]
    make: [check] Error 35 (ignored)

    /Johan
    Johan Guest

  2. #2

    Default Re: pthread / UDP support on OS X?

    In article <400c5988$wineasy.se>,
    Johan Lindh <getridofthis.se> wrote:
     
     
     
     

    You really should try running under a debugger a bit. :) That'd tell
    you that your counter isn't being changed in a bizarre way; instead,
    it's ping-ponging back and forth as your two counter threads run.

    As for why your count_down thread is continuing to run, that's because
    your pbThreadDestroy() function is attempting to stop the thread by
    calling pthread_cancel(). From Mac OS X's man page for pthread_cancel:

    "The pthread_cancel() function requests that thread be canceled. The
    target thread's cancelability state and type determines when the
    cancellation takes effect."

    In other words, pthread_cancel() is a request, not a requirement. In
    general (as far as I know; I'm not a pthreads expert), pthreads are only
    canceled on any system when they are at cancellation points. Mac OS X
    currently has very few cancellation points for pthreads, so
    pthread_cancel() essentially only has an impact if the canceled thread
    calls pthread_testcancel(). Since your count_down thread doesn't call
    pthread_testcancel(), it continues to run.

    Hope this helps,
    Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  3. #3

    Default Re: pthread / UDP support on OS X?

    Eric Albert wrote:
     

    No, it isn't. Please check the code. If X threads are running, and they
    all lock a common mutex before incrementing a volatile variable, then
    the variable can (logically) never decrement in value. It does.

    "My two counter threads"? Please look at the code before attempting to
    answer. There are 40 of them. Unless you're referring to the previous
    test in the same file..? But why do that? That test (thread starvation)
    succeeds.
     

    From the README in my package:

    On Mac OS/X, pthread_cancel() isn't implemented for
    asynchronous calls, so pbThreadDestroy() won't work.
    Apple may have fixed that by the time you read this,
    though.
     

    It didn't, but I appreciate the effort.

    /J
    Johan Guest

  4. #4

    Default Re: pthread / UDP support on OS X?

    In article <400d1400$wineasy.se>,
    Johan Lindh <getridofthis.se> wrote:
     
    >
    > No, it isn't. Please check the code.[/ref]

    I did -- I looked at it, built it, and inserted printfs.
     

    I'm afraid I don't have a copy of the code around any more, but I was
    looking at test_thread.c. There was a test with count_down and count_up
    threads, and the count_down thread was supposed to be killed. The
    pbThreadDestroy assertion was triggered because the thread wasn't
    killed, and that caused subsequent error messages from that file as well.

    -Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  5. #5

    Default Re: pthread / UDP support on OS X?

    Eric Albert wrote: 
    >>
    >>No, it isn't. Please check the code.[/ref]
    >
    >
    > I did -- I looked at it, built it, and inserted printfs.
    >

    >
    >
    > I'm afraid I don't have a copy of the code around any more, but I was
    > looking at test_thread.c. There was a test with count_down and count_up
    > threads, and the count_down thread was supposed to be killed. The
    > pbThreadDestroy assertion was triggered because the thread wasn't
    > killed, and that caused subsequent error messages from that file as well.[/ref]

    Doh! You're right, of course. I've put in a fallback for the expected
    thread destroying failiure, and with both those counter threads out of
    action, the other thread tests run just fine.

    I don't suppose you had an idea why those UDP calls are failing in the
    test_netudp test..?

    /J
    Johan Guest

Similar Threads

  1. Pthread compile problem
    By Philip Edward Lewis in forum AIX
    Replies: 6
    Last Post: November 30th, 01:47 AM
  2. Problem compiling pthread
    By Stu in forum AIX
    Replies: 4
    Last Post: November 1st, 07:57 PM
  3. stack size of pthread during run time
    By Sting in forum UNIX Programming
    Replies: 4
    Last Post: October 20th, 01:07 PM
  4. pthread mutex and data alignment
    By T.R.Bennett in forum AIX
    Replies: 3
    Last Post: August 29th, 02:06 PM
  5. select, socketpair, pthread on OS X
    By Matthew in forum UNIX Programming
    Replies: 6
    Last Post: August 27th, 03:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139