about threads (here: increasing thread IDs)
Jost Berthold
berthold at Mathematik.Uni-Marburg.de
Wed Jun 21 04:28:43 EDT 2006
Hi Seth,
perhaps this will help you, some information from the implementation
side concerning your question about threadIDs:
Related code lived in rts/Schedule.c, has recently moved to
rts/Threads.* in the head.
The ThreadID assigned by the RTS is continuously increasing, and
declared to be StgInt32 (32 bits usually).
So you might get int overflows when running your server for a *fairly*
long time. OTOH, depending on what you want to do with the ThreadIDs
that forkIO returns, IMHO you could just *ignore* these overflows.
From your short description of how the servers work, you know an upper
bound on the no. of running threads (6), but not on their time to live.
So IMHO the worst case scenario would be:
a new thread for a client gets ID n
... 2^32 other server threads get spawned
another new thread for a client gets the same ID n again
...
one of the threads supposed to terminate (killThread n)
AFAICT, the killThread action will arbitrarily choose one of the two.
HTH
Jost
------ you wrote ------
Date: Tue, 20 Jun 2006 23:22:26 -0400
From: Seth Kurtzberg <seth at cql.com>
Subject: Re: FFI: number of worker threads?
To: "Li, Peng" <ringer9cs+ghc at gmail.com>
Cc: glasgow-haskell-users at haskell.org
Another related question. I have some threaded applications running
which are servers and run continuously. A thread is spawned for each
new connection, and the thread exits when the client terminates.
I've noticed that the thread ID increases. On one process I checked
today I am up to thread number 3300. The number of running threads is
not increasing; only six threads are running on this particular process.
The threads are cleaned up and exit. The thread _ID_ is continually
increasing.
Is this going to cause a problem when the thread ID exceeds some value?
Do I have to force the server process to recycle periodically?
...
More information about the Glasgow-haskell-users
mailing list