BVLC/caffe — pull request #348 by jeffdonahue (2014-04-22 04:18:28+00:00)
Title: DataLayer singleton bugfix

I believe this fully fixes the apparent issue with the RNG mentioned in #335, (which it turns out my PR #336 did nothing to address, but was still nonetheless an improvement).

Basically, the DataLayer prefetch thread has no knowledge of the main Caffe thread's `Caffe` singleton, but it was making a call to Caffe::phase(), which resulted in the DataLayer constructing its own brand new Caffe singleton instance, and then, my theory at least is that somehow the destruction of this singleton instance when the thread exits isn't correctly handled and interferes with main thread memory? Not entirely sure about that explanation, but I do know that after at least 25 runs of the imagenet architecture with this change, I have not seen a segfault (vs. current dev which segfaults 25-75% of the time).

I also thought I'd uncovered a long-standing `DataLayer` bug as it seemed like the Caffe::phase() call in the prefetch thread should always return the default phase (TRAIN), but I added debug printouts inside the prefetch thread and ran from dev and it turns out that somehow the prefetch thread's phase is already being set correctly, but I'm pretty sure I have no idea how...