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/psphot/src/psphotSourceStats.c

    r28013 r28405  
    33// convert detections to sources and measure their basic properties (moments, local sky, sky
    44// variance) Note: this function only generates sources for the new peaks (peak->assigned).
    5 // The new sources are added to any existing sources on detections->newSources.  The sources 
     5// The new sources are added to any existing sources on detections->newSources.  The sources
    66// on detections->allSources are ignored.
    77bool psphotSourceStats (pmConfig *config, const pmFPAview *view, const char *filerule, bool setWindow)
     
    2222    // loop over the available readouts
    2323    for (int i = 0; i < num; i++) {
    24         // if (i == chisqNum) continue; // skip chisq image
     24        // if (i == chisqNum) continue; // skip chisq image
    2525        if (!psphotSourceStatsReadout (config, view, filerule, i, recipe, setWindow)) {
    2626            psError (PSPHOT_ERR_CONFIG, false, "failed to find initial detections for %s entry %d", filerule, i);
     
    9191    // generate the array of sources, define the associated pixel
    9292    if (!detections->newSources) {
    93         detections->newSources = psArrayAllocEmpty (peaks->n);
     93        detections->newSources = psArrayAllocEmpty (peaks->n);
    9494    }
    9595    sources = detections->newSources;
     
    107107        // create a new source
    108108        pmSource *source = pmSourceAlloc();
    109         source->imageID = index;
     109        source->imageID = index;
    110110
    111111        // add the peak
     
    184184            if (!psThreadJobAddPending(job)) {
    185185                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
    186                 psFree (job);
    187186                psFree(detections->newSources);
    188187                return false;
    189188            }
    190             psFree(job);
    191189        }
    192190
     
    194192        if (!psThreadPoolWait (false)) {
    195193            psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS");
    196             psFree(detections->newSources);
     194            psFree(detections->newSources);
    197195            return false;
    198196        }
     
    315313            if (!psThreadJobAddPending(job)) {
    316314                psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS");
    317                 psFree (job);
    318315                return NULL;
    319316            }
    320             psFree(job);
    321317        }
    322318
     
    380376        pmSource *source = sources->data[i];
    381377
    382         if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;
    383         source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
     378        if (source->tmpFlags & PM_SOURCE_TMPF_MOMENTS_MEASURED) continue;
     379        source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
    384380
    385381        // skip faint sources for moments measurement
Note: See TracChangeset for help on using the changeset viewer.