Commit b2b5bb58 authored by Eric Cano's avatar Eric Cano
Browse files

Attempted fix to the bug CASTOR-4736: Race condition in unit tests...

Attempted fix to the bug CASTOR-4736: Race condition in unit tests (tapeServer_DataTransferSessionMissingFilesMigration_Test)

The explicit separation between the decrement of the counter in AtomicCounter::operator-- was not enough
to prevent the deadlock, which was reproduced.

After just adding storage of the value in a variable and printout in DiskReadThreadPool::DiskReadWorkerThread::run,
the problem seemed to be gone after about one hour of loop testing.

I commit this change and push it to teamcity to get more chances of reproducing the issue (if it is still present).
If this patch solves the problem, we might be facing a misguided compiler optimisation.
parent da5b769f
......@@ -44,7 +44,13 @@ template <class T> struct AtomicCounter{
}
T operator -- () {
MutexLocker ml(&m_mutex);
return --m_val;
// Store the return value in a local variable
// instead of returning --m_val, which is a reference
// to the value. If this reference to value gets cast into value
// and evaluated after the destruction of ml, we have a race
// condition (which we seemed to experience under rare circumstances).
T ret = --m_val;
return ret;
}
operator T() const {
MutexLocker ml(&m_mutex);
......
......@@ -162,9 +162,14 @@ void DiskReadThreadPool::DiskReadWorkerThread::run() {
} //end of while(1)
// We now acknowledge to the task injector that read reached the end. There
// will hence be no more requests for more. (last thread turns off the light)
if (0 == --m_parent.m_nbActiveThread) {
int remainingThreads = --m_parent.m_nbActiveThread;
if (!remainingThreads) {
m_parent.m_injector->finish();
m_lc.log(LOG_INFO, "Signaled to task injector the end of disk read threads");
} else {
castor::log::ScopedParamContainer params(m_lc);
params.add("remainingThreads", remainingThreads);
m_lc.log(LOG_DEBUG, "Will not signal the end to task injector yet");
}
m_parent.addThreadStats(m_threadStat);
logWithStat(LOG_INFO, "Finishing of DiskReadWorkerThread");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment