pthread_getspecific fails after some calls in the same thread(task?)

Heinz Junkes junkes at fhi-berlin.mpg.de
Mon Jul 24 10:01:42 UTC 2017


I'm still trying to port EPICS to RTEMS 4.12 (4.11.99). I try to make the whole with posix threads
and run into the following issue by using pthread_getspecific (I get the same for me not expected result
when I use __thread variable instead).

In a function “once” called bei pthread_once I create a thread bounded key with
pthread_key_create(&getpthreadInfo,0);

The “key” is defined with
static epicsThreadOSD *createImplicit(void);

 static void epicsThreadInit(void)
  {
      static pthread_once_t once_control = PTHREAD_ONCE_INIT;
      int status = pthread_once(&once_control,once);
      checkStatusQuit(status,"pthread_once","epicsThreadInit");
  }


If I print out the position and value of this created key with 
fprintf(stderr,"getpthreadInfo content = 0x%lx at %p\n",getpthreadInfo,&getpthreadInfo );

I get during run-time :

getpthreadInfo content = 0x13010003 at 0x22b6b8

and with further running the following function get called:

epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf(void) {
  epicsThreadOSD *pthreadInfo;

     epicsThreadInit();
     fprintf(stderr,"epicsThreadGetIdSelf: getpthreadInfo content = 0x%lx at %p\n",getpthreadInfo,&getpthreadInfo );
     pthreadInfo = (epicsThreadOSD *)pthread_getspecific(getpthreadInfo);
     fprintf(stderr,"epicsThreadGetIdSelf:getspecific getpthreadInfo for tid 0x%x = %p\n", pthread_self(), pthreadInfo);
     if(pthreadInfo==NULL)
         pthreadInfo =  createImplicit();
     assert( pthreadInfo );
     return(pthreadInfo);
  }

There is just one task (posix thread tid 0xb010001) running which does different initializations …

works so far:

…
epicsThreadOnce id = 0x0, func to call : 0x6346c
epicsThreadGetIdSelf: getpthreadInfo content = 0x13010003 at 0x22b6b8
epicsThreadGetIdSelf:getspecific getpthreadInfo for tid 0xb010001 = 0x2bcb58
epicsThreadOnce id = 0x22b6d4, func to call : 0x504d4
epicsThreadOnce id = 0x0, func to call : 0x4b08c
epicsThreadGetIdSelf: getpthreadInfo content = 0x13010003 at 0x22b6b8
epicsThreadGetIdSelf:getspecific getpthreadInfo for tid 0xb010001 = 0x2bcb58
…
but at one point ( 7 times it goes well, can this be a hint?) it fails:

epicsThreadOnce id = 0x0, func to call : 0x41410
epicsThreadGetIdSelf: getpthreadInfo content = 0x13010003 at 0x22b6b8
epicsThreadGetIdSelf:getspecific getpthreadInfo for tid 0xb010001 = 0x0


Any idea what might go wrong? Am I doing something wrong?
Unfortunately, I do not understand the assignment of rtems-tasks to posix-threads ;-(

Thank you,
Heinz







-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2593 bytes
Desc: not available
URL: <http://lists.rtems.org/pipermail/users/attachments/20170724/b4b438cb/attachment.bin>


More information about the users mailing list