IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 18, 2010, 2:25:38 PM (16 years ago)
Author:
Paul Price
Message:

Discovered a race condition in the threading process. The thread process was: psThreadJobAlloc, populate job with arguments, psThreadJobAddPending, psFree the job. This is not thread-safe, because we're decrementing the job's reference counter while the reference count is also being fiddled within the thread system (psThread.c; by pulling the job off the 'pending' queue and putting it on the 'done' queue). The reference count fiddling within the thread system was protected by a mutex, but the external free was not. Therefore, I'm pulling the free into the thread system so it can be protected (without the user having to worry about locks to do the simple case). This means that the user should no longer touch the job once he hands it over to the thread system (unless it's protected by calls to psThreadLock/psThreadUnlock, or it's on the other side of psThreadPoolWait from all the adds so that the threads aren't doing anything).

File:
1 edited

Legend:

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

    r28402 r28405  
    9999bool psThreadJobAddPending(psThreadJob *job)
    100100{
    101     PS_ASSERT_THREAD_JOB_NON_NULL(job, false);
     101    if (!job) {
     102        // Asking for a no-op
     103        return true;
     104    }
    102105
    103106    psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job
     
    114117        }
    115118        psListAdd(done, PS_LIST_TAIL, job);
    116 
     119        psFree(job);
    117120        return task->function(job);
    118121    }
     
    123126    }
    124127    psListAdd(pending, PS_LIST_TAIL, job);
     128    psFree(job);
    125129    psThreadUnlock();
    126130
     
    279283    for (int i = 0; i < nThreads; i++) {
    280284        psThread *thread = pool->data[i] = psThreadAlloc(); // Thread for pool
    281         if (!pthread_create(&threads[i], NULL, psThreadLauncher, thread)) {
     285        if (pthread_create(&threads[i], NULL, psThreadLauncher, thread)) {
    282286            psAbort("Unable to create thread");
    283287        }
Note: See TracChangeset for help on using the changeset viewer.