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.h

    r28402 r28405  
    7373
    7474/// Add a pending job to the queue
     75///
     76/// This function swallows the provided job, so that the user no longer owns it.  This is because freeing the
     77/// job is not thread-safe (its reference count is being changed within the threads) so we handle it ourselves
     78/// and absolve the user from all responsibility.  If the user stores the job, he should only access it while
     79/// threads are processing in code protected by psThreadLock/psThreadUnlock.
    7580bool psThreadJobAddPending(psThreadJob *job);
    7681
    7782/// Get a job off the queue of pending jobs
     83///
     84/// This function is not thread-safe.  Protect with psThreadLock/psThreadUnlock if threads are running.
    7885psThreadJob *psThreadJobGetPending(void);
    7986
    8087/// Get a job off the queue of done jobs
     88///
     89/// This function is not thread-safe.  Protect with psThreadLock/psThreadUnlock if threads are running.
    8190psThreadJob *psThreadJobGetDone(void);
    8291
     
    115124bool psThreadPoolFinalize(void);
    116125
    117 
     126#if 0
    118127/// Add thread-specific data
    119128///
     
    134143bool psThreadDataRemove(const char *name // Name of data
    135144    );
    136 
     145#endif
    137146
    138147/// @}
Note: See TracChangeset for help on using the changeset viewer.