<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
The algorithms for thread id assignment vary on the platforms.<BR>
 <BR>
In posix user threads and Win32 threads, it appears to be a number that increments for every new thread.<BR>
Not sure what happens after 2 or 4 billion.<BR>
 <BR>
On pthreads, it appears to be, well, we maintain an array of threads.<BR>
So it is a number between 0 and n where n is the maximum number of threads that have<BR>
"ever" been running at the same time. With presumably aggressive reuse of ids.<BR>
 <BR>
Ok?<BR>
 <BR>
They should all use the same?<BR>
 <BR>
It's just that I'm looking at the Win32 code, comparing it to the pthread code:<BR>
 <BR>
Win32:<BR>
    LockMutex(threadMu);<BR>    cl := self.closure;<BR>      self.id := nextId;  INC (nextId);<BR>    UnlockMutex(threadMu);<BR><BR>
Pthread doesn't have this code.<BR>
I don't believe self.closure needs a lock.<BR>
And per above, pthreads doesn't need protection here for id, since it is handled elsewhere.<BR>
 <BR>
I know this was just discussed in a sense -- MyId is for debugging/diagnostics only and its value can't be depended on for much.<BR>
 <BR>
The are obvious advantages/disadvantages to the two schemes.<BR>
Win32/Posix recycle "never", so debugging probably easier.<BR>
Pthread doesn't waste time/space on the id.<BR>
 <BR>
 - Jay<BR><BR>                                           </body>
</html>