Menu

#695 Add "TID" argument to Unix version of SysQueryProcess()

None
unread
nobody
None
none
1
2017-10-10
2017-10-10
No

Surprisingly, the Rexx utilty function SysQueryProcess() has no "TID" (thread id) argument on Unix. As this value may be important for debugging multithreaded Rexx programs that work on Windows as well as on Unix the Unix version of SysQueryProcess should accept the argument "TID" and return the current thread id.

The following snippets from BSF4ooRexx.cc work on Linux and MacOSX:

----- cut here -----

const size_t RGF_TID_STRING_WIDTH    = 40;  

    // query current TID and return it
inline thread_id_t RgfGetTID()
{
    return
        #ifdef WINDOWS
            GetCurrentThreadId();
        #else // anything else
            pthread_self();
        #endif
}

RexxRoutine0(RexxStringObject, BsfGetTID)    
{
   thread_id_t tid=RgfGetTID();
   char    *strTid=new char[RGF_TID_STRING_WIDTH];
   snprintf( strTid, RGF_TID_STRING_WIDTH, "%lu%c", ((unsigned long) tid), 0);  // create decimal number
   RexxStringObject rso=context->String(strTid);
   delete[] strTid;

   return rso;
}

----- cut here -----

Discussion

Anonymous
Anonymous

Add attachments
Cancel