IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 18, 2010, 10:48:42 AM (16 years ago)
Author:
Paul Price
Message:

Pulling pthread out of psThread type because it's unnecessary (never used) and subject to a (write) race condition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psThread.c

    r28400 r28402  
    3838static psList *pending = NULL;          // queue of pending jobs
    3939static psList *done = NULL;             // queue of done jobs
     40static pthread_t *threads = NULL;       // array of the POSIX thread handles
    4041static psArray *pool = NULL;            // array of defined threads
    4142static psHash *tasks = NULL;            // List of defined tasks
    4243static psArray *tsd = NULL;             // Thread-specific data
    43 
    4444
    4545/***** basic thread functions *****/
     
    265265bool psThreadPoolInit(int nThreads)
    266266{
    267     if (pool) {
     267    if (pool || threads) {
    268268        psAbort("psThreadsInit already called");
    269269    }
     
    276276
    277277    pool = psArrayAlloc(nThreads);
     278    threads = psAlloc(nThreads * sizeof(pthread_t));
    278279    for (int i = 0; i < nThreads; i++) {
    279         psThread *thread = psThreadAlloc(); // Thread for pool
    280         int success = pthread_create(&thread->pt, NULL, psThreadLauncher, thread);
    281         psAssert(!success, "Unable to start thread");
    282         pool->data[i] = thread;
     280        psThread *thread = pool->data[i] = psThreadAlloc(); // Thread for pool
     281        if (!pthread_create(&threads[i], NULL, psThreadLauncher, thread)) {
     282            psAbort("Unable to create thread");
     283        }
    283284    }
    284285    return true;
     
    376377    pool = NULL;
    377378
     379    psFree(threads);
     380    threads = NULL;
     381
    378382    psFree(tasks);
    379383    tasks = NULL;
Note: See TracChangeset for help on using the changeset viewer.