Skip to content

Commit 28e7edd

Browse files
committed
Fix race condition on spike sorter
1 parent 8d9b08e commit 28e7edd

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

Source/Plugins/SpikeSorter/SpikeSortBoxes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void SpikeSortBoxes::projectOnPrincipalComponents(SorterSpikePtr so)
884884
bPCAJobSubmitted = true;
885885
bRePCA = false;
886886
// submit a new job to compute the spike buffer.
887-
PCAjob job(spikeBuffer,pc1,pc2, &pc1min, &pc2min, &pc1max, &pc2max, &bPCAjobFinished);
887+
PCAjob job(spikeBuffer,pc1,pc2, &pc1min, &pc2min, &pc1max, &pc2max, bPCAjobFinished);
888888
computingThread->addPCAjob(job);
889889
}
890890
}
@@ -1706,7 +1706,7 @@ static double sqrarg;
17061706
#define SQR(a) ((sqrarg = (a)) == 0.0 ? 0.0 : sqrarg * sqrarg)
17071707

17081708
PCAjob::PCAjob(SorterSpikeArray& _spikes, float* _pc1, float* _pc2,
1709-
float* pc1Min, float* pc2Min, float* pc1Max, float* pc2Max, bool* _reportDone) : spikes(_spikes), reportDone(_reportDone)
1709+
float* pc1Min, float* pc2Min, float* pc1Max, float* pc2Max, std::atomic<bool>& _reportDone) : spikes(_spikes), reportDone(_reportDone)
17101710
{
17111711
cov = nullptr;
17121712
pc1 = _pc1;
@@ -2170,7 +2170,7 @@ void PCAcomputingThread::run()
21702170
J.computeSVD();
21712171

21722172
// 4. Report to the spike sorting electrode that PCA is finished
2173-
*(J.reportDone) = true;
2173+
J.reportDone = true;
21742174
}
21752175
}
21762176

@@ -2239,4 +2239,4 @@ const SpikeChannel* SorterSpikeContainer::getChannel() const
22392239
int64 SorterSpikeContainer::getTimestamp() const
22402240
{
22412241
return timestamp;
2242-
}
2242+
}

Source/Plugins/SpikeSorter/SpikeSortBoxes.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2828
#include <algorithm> // std::sort
2929
#include <list>
3030
#include <queue>
31+
#include <atomic>
3132

3233
class SorterSpikeContainer : public ReferenceCountedObject
3334
{
@@ -180,7 +181,7 @@ class PCAjob
180181
{
181182
public:
182183
PCAjob(SorterSpikeArray& _spikes, float* _pc1, float* _pc2,
183-
float*, float*, float*, float*, bool* _reportDone);
184+
float*, float*, float*, float*, std::atomic<bool>& _reportDone);
184185
~PCAjob();
185186
void computeCov();
186187
void computeSVD();
@@ -189,7 +190,7 @@ class PCAjob
189190
SorterSpikeArray spikes;
190191
float* pc1, *pc2;
191192
float* pc1min, *pc2min, *pc1max, *pc2max;
192-
bool* reportDone;
193+
std::atomic<bool>& reportDone;
193194
private:
194195
int svdcmp(float** a, int nRows, int nCols, float* w, float** v);
195196
float pythag(float a, float b);
@@ -303,7 +304,8 @@ class SpikeSortBoxes
303304
SorterSpikeArray spikeBuffer;
304305
int bufferSize,spikeBufferIndex;
305306
PCAcomputingThread* computingThread;
306-
bool bPCAJobSubmitted,bPCAcomputed,bRePCA,bPCAjobFinished ;
307+
bool bPCAJobSubmitted,bPCAcomputed,bRePCA;
308+
std::atomic<bool> bPCAjobFinished ;
307309

308310

309311
};

0 commit comments

Comments
 (0)