On Mon, Jan 30, 2012 at 1:21 PM, Dougal Sutherland <dougal@gmail.com> wrote:
I have some code using boost::thread that works fine when it's called directly from a main() function, but (almost) always segfaults and/or hangs forever when called from a Matlab mex interface. I don't know whether that's due to the Matlab interface breaking something about boost::thread or if the different environment is revealing a flaw with my code.

As it turns out, I get the same results with a trivial program: 

void doNothing() { return; }

void doWork() {
    boost::thread t1(doNothing);
    t1.join();
}

This runs fine standalone -- though DRD in Valgrind 3.7 gives me tons of errors when I run this with Boost 1.48 on my Mac -- but segfaults intermittently when run from matlab.

Is this definitely a matlab problem? I'm not sure how it really could be, but it also seems incredibly unlikely that there would be a race condition or something in such a basic component of Boost.Thread.

Any thoughts?