Closed Bug 23951 Opened 26 years ago Closed 26 years ago

Add thread pool feature

Categories

(NSPR :: NSPR, defect, P3)

x86
Windows NT
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: srinivas, Assigned: srinivas)

Details

Attachments

(3 files)

Add thread pool feature to NSPR. New files: nsprpub/pr/include/prtpool.h (API) nsprpub/pr/src/misc/prptool.c (implementation) nsprpub/pr/tests/thrpool_server.c (test program) nsprpub/pr/tests/thrpool_client.c Modified files: nsprpub/src/Makefile nsprpub/src/misc/Makefile nsprpub/pr/tests/makefile
Status: NEW → ASSIGNED
The following files are checked in: /cvsroot/mozilla/nsprpub/pr/include/prtpool.h initial revision: 1.1 /cvsroot/mozilla/nsprpub/pr/src/Makefile new revision: 3.29; previous revision: 3.28 /cvsroot/mozilla/nsprpub/pr/src/misc/Makefile new revision: 3.10; previous revision: 3.9 /cvsroot/mozilla/nsprpub/pr/src/misc/prtpool.c initial revision: 3.1 /cvsroot/mozilla/nsprpub/pr/tests/Makefile new revision: 3.47; previous revision: 3.46 /cvsroot/mozilla/nsprpub/pr/tests/thrpool_client.c initial revision: 3.1 /cvsroot/mozilla/nsprpub/pr/tests/thrpool_server.c initial revision: 3.1
Status: ASSIGNED → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
Marking the bug resolved.
Comments on attachment 4859 [details] [diff] [review]: 1. I changed the types JobFn and Jobfn to PRJobFn. 2. I changed the type of the stacksize argument of PR_CreateThreadPool to PRUint32, to be consistent with PR_CreateThread.
Checked in patch 4934. /cvsroot/mozilla/nsprpub/pr/include/prtpool.h,v <-- prtpool.h new revision: 1.1.2.2; previous revision: 1.1.2.1 /cvsroot/mozilla/nsprpub/pr/src/misc/prtpool.c,v <-- prtpool.c new revision: 3.1.2.3; previous revision: 3.1.2.2
Comments on the thread pool API (prtpool.h): 1. The 'socket' field of struct PRJobIoDesc suggests that the fd must be a socket. However, it seems that any pollable fd (such as a pollable event) can be used. I would name it 'fd' and document that it must be a socket. 2. It's not clear how long the caller of PR_QueueJob_Read, etc. needs to keep the PRJobIoDesc structure around after passing it to the function. It seems that the only reason the caller needs to keep the PRJobIoDesc around is to read its 'error' field (the error code). An alternative design is to make the error code the second argument to a new kind of job function: typedef void (PR_CALLBACK *PRJobIoFn) (void *arg, PRErrorCode error); Then the prototype of PR_QueueJob_Read, etc. would become: NSPR_API(PRJob *) PR_QueueJob_Read(PRThreadPool *tpool, PRFileDesc *socket, PRIntervalTime timeout, PRJobIoFn fn, void *arg, PRBool joinable); 3. It's not clear how to properly shut down and destroy a thread pool. Sample code of the lifetime of a thread pool, from creation to end, would be nice. It also seems that PR_ShutdownThreadPool and PR_JoinThreadPool can be combined into one function, unless we want to do other things in between or have two different threads call PR_ShutdownThreadPool and PR_JoinThreadPool. 4. I don't think joinable job is an essential feature because it can be easily implemented by the caller in the job function. But it should be a useful convenience feature.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: