[Avila] pthread behavior issues on 2348/0.6

gw at lunstad.com gw at lunstad.com
Fri May 12 16:47:52 EDT 2006


Hi Folks,

I am seeing strange threading behavior on the 2348. Specifically, I would
expect a created thread to run with its own threadid, accessible through
the pthread_self() call. In the (simple) attached code, this is not the
case when running on the 2348 but is the case for an x86 linux box (as I
would expect).

Are my assumptions about threadids wrong? This is breaking an application
I am hoping to port, so any workaround would be greatly appreciated.

Thanks,

Andrew

############ Code (apologies for wrapping) ###########

#include <stdio.h>
#include <pthread.h>

#define TCOUNT 5

int global_threadid;

static void mythread(void *arg)
{
    sleep(3);
    if ( global_threadid != pthread_self() ) {
        printf("mythread: Expected.  pthread_self = %x != global_threadid
-- index = %d\n", pthread_self(), (int)arg);
    } else {
        printf("mythread: UNEXPECTED pthread_self = %x SAME AS
global_threadid -- index = %d\n", pthread_self(), (int)arg);
    }
    fflush(stdout);
}

main(int argc, char argv[][])
{
    int i;
    pthread_t threads[TCOUNT];

    global_threadid = pthread_self();
    printf("main : global_threadid = %x\n", global_threadid);

    for(i=0;i<TCOUNT; i++) {
        pthread_create(&threads[i], NULL, mythread, (void *)i);
        printf("main : created thread %x index = %d\n", threads[i], i);
        fflush(stdout);
        sleep(1);
    }
    sleep(TCOUNT+4);
}

############### Log on Gateworks ####################

# ./a.out
main : global_threadid = 400
main : created thread 408 index = 0
main : created thread 809 index = 1
main : created thread c0b index = 2
mythread: Expected.  pthread_self = 408 != global_threadid -- index = 0
main : created thread 100c index = 3
mythread: Expected.  pthread_self = 809 != global_threadid -- index = 1
main : created thread 140d index = 4
mythread: UNEXPECTED pthread_self = 400 SAME AS global_threadid -- index = 2
mythread: UNEXPECTED pthread_self = 400 SAME AS global_threadid -- index = 3
mythread: Expected.  pthread_self = 140d != global_threadid -- index = 4

################## Log on x86(SuSE) ################
avila/snapgear> ./a.out
main : global_threadid = 4003e920
main : created thread 40355bb0 index = 0
main : created thread 40556bb0 index = 1
main : created thread 40757bb0 index = 2
mythread: Expected.  pthread_self = 40355bb0 != global_threadid -- index = 0
main : created thread 40958bb0 index = 3
mythread: Expected.  pthread_self = 40556bb0 != global_threadid -- index = 1
main : created thread 40b59bb0 index = 4
mythread: Expected.  pthread_self = 40757bb0 != global_threadid -- index = 2
mythread: Expected.  pthread_self = 40958bb0 != global_threadid -- index = 3
mythread: Expected.  pthread_self = 40b59bb0 != global_threadid -- index = 4





More information about the Avila mailing list