We came across a very new bug in AzEl.cc today, which must've been introduced via injudicious cut-n-paste. I thought I'd post it to the mailing list since it illustrates an important point of writing nodes. The code went something like:
evaluateTensors ()
{
.
if( obs_name_.empty() )
{
Thread::Mutex::Lock lock(aipspp_mutex); // AIPS++ is not
thread-safe, so lock mutex
const Vells& vx = *(args[1][0]);
...
}
else
{
Thread::Mutex::Lock lock(aipspp_mutex); // AIPS++ is not
thread-safe, so lock mutex
....
}
}
The 'lock' object is a a lock on the aips++ mutex; the lock is released as soon as the C++ variable 'lock' goes out of scope, which in this case is at the closing brace of the "if" or "else" clause. Unfortunately, there's more code involving aips++ at the main level, after the if/else -- which means that in multithreaded mode everything breaks down as multiple threads calling on aips++ trip over each other.
The moral of course is to (a) always protect aips++ calls with a lock on aipspp_mutex, (b) pay attention to the scope of your mutex locks, and (c) cut-n-paste with care!
Cheers, Oleg
