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/psphotMagnitudes.c

    r28098 r28405  
    1818    // loop over the available readouts
    1919    for (int i = 0; i < num; i++) {
    20         if (i == chisqNum) continue; // skip chisq image
    21 
    22         // find the currently selected readout
    23         pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
    24         psAssert (file, "missing file?");
    25 
    26         pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
    27         psAssert (readout, "missing readout?");
    28 
    29         pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
    30         psAssert (detections, "missing detections?");
    31 
    32         psArray *sources = detections->allSources;
    33         psAssert (sources, "missing sources?");
    34 
    35         pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    36         psAssert (psf, "missing psf?");
    37 
    38         if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {
     20        if (i == chisqNum) continue; // skip chisq image
     21
     22        // find the currently selected readout
     23        pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, i); // File of interest
     24        psAssert (file, "missing file?");
     25
     26        pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     27        psAssert (readout, "missing readout?");
     28
     29        pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     30        psAssert (detections, "missing detections?");
     31
     32        psArray *sources = detections->allSources;
     33        psAssert (sources, "missing sources?");
     34
     35        pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
     36        psAssert (psf, "missing psf?");
     37
     38        if (!psphotMagnitudesReadout (config, recipe, view, readout, sources, psf)) {
    3939            psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i);
    40             return false;
    41         }
     40            return false;
     41        }
    4242    }
    4343    return true;
     
    5050
    5151    if (!sources->n) {
    52         psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes");
    53         return true;
    54     }
    55        
     52        psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping source magnitudes");
     53        return true;
     54    }
     55
    5656    psTimerStart ("psphot.mags");
    5757
     
    122122            if (!psThreadJobAddPending(job)) {
    123123                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    124                 psFree (job);
    125124                return false;
    126125            }
    127             psFree(job);
    128126
    129127# if (0)
     
    184182        }
    185183
    186         // clear the mask bit and set the circular mask pixels
    187         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    188         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
     184        // clear the mask bit and set the circular mask pixels
     185        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     186        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
    189187
    190188        status = pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal
    191189        if (status && isfinite(source->apMag)) Nap ++;
    192190
    193         // clear the mask bit
    194         psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
     191        // clear the mask bit
     192        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    195193
    196194        // re-subtract the object, leave local sky
     
    273271            if (!psThreadJobAddPending(job)) {
    274272                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    275                 psFree (job);
    276273                return false;
    277274            }
    278             psFree(job);
    279 
    280275        }
    281276
Note: See TracChangeset for help on using the changeset viewer.