|
Boost Users : |
Subject: [Boost-users] Creating a boost thread in a matlab mex file causes matlab to crash
From: bjs109 (ben.j.stephens_at_[hidden])
Date: 2009-06-23 06:59:59
I'm having some issues getting matlab and boost threads to work together. I'm
posting here and a number of other places as I don't think this problem fits
into any one domain.
Specifically, whenever I try to use boost threads within a mex file, it
causes matlab to crash.
My test program is:
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include "mex.h"
class TestClass
{
public:
void run();
};
void TestClass::run()
{
for (int n = 0; n < 5; n++)
{
sleep(1);
}
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
TestClass tc;
boost::thread *pThread = new boost::thread(boost::bind(&TestClass::run,
&tc));
pThread->join();
}
The matlab crash output is as follows
Configuration:
MATLAB Version: 7.7.0.471 (R2008b)
MATLAB License: 166534
Operating System: Linux 2.6.18-128.1.6.el5.centos.plusPAE #1 SMP Thu Apr 2
13:33:12 EDT 2009 i686
GNU C Library: 2.5 stable
Processor ID: x86 Family 6 Model 7 Stepping 10, GenuineIntel
Virtual Machine: Java 1.6.0_04 with Sun Microsystems Inc. Java
HotSpot(TM) Client VM mixed mode
Default Encoding: ISO-8859-1
Fault Count: 1
Register State:
eax = 00d6bf00 ebx = 003cf590
ecx = 040571cc edx = 040571d0
esi = 04057124 edi = 00000000
ebp = a72ba3b8 esp = a72ba37c
eip = 56e58955 flg = 00010246
Stack Trace:
[0] 0x56e58955(0x04057124, 2, 2, 2)
[1] libpthread.so.0:0x0038949b(0xa72bab90, 0, 0, 0)
Running GDB on the application reveals that at the time of crashing, there
are 13 threads. The backtrace for the created thread / parent thread is
given below:
Thread 13 (created thread)
#0 0x56e58955 in ?? ()
#1 0x0031daf2 in thread_proxy (param=0x4241124) at
./boost/function/function_template.hpp:647
#2 0x0067049b in start_thread () from /lib/libpthread.so.0
#3 0x005c742e in clone () from /lib/libc.so.6
Thread 12 (parent thread)
#0 0x003da410 in __kernel_vsyscall ()
#1 0x00674595 in pthread_cond_wait@@GLIBC_2.3.2 () from
/lib/libpthread.so.0
#2 0x0031b164 in boost::detail::condition_impl::do_wait (this=0x4241140,
pmutex=0x4241124) at libs/thread/src/condition.cpp:371
#3 0x0031dd51 in thread (this=0x96c9c28, threadfunc=@0x42411cc) at
./boost/thread/condition.hpp:150
#4 0x00e9a7c2 in mexFunction (nlhs=0, plhs=0x42418fc, nrhs=0,
prhs=0x424195c) at threadtest.cpp:25
#5 0x003e584f in mexRunMexFile () from
/usr/local/matlabR2008b/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmex.so
I am using:
CentOS version 5.3
Boost version 1.33.1 (the one that comes with CentOS 5.3)
Matlab R2008b release
GCC version 4.1.2 (again, the one that comes with CentOS 5.3)
The line used to compile the code:
mex -g threadtest.cpp -lboost_thread
Any ideas?
-- View this message in context: http://www.nabble.com/Creating-a-boost-thread-in-a-matlab-mex-file-causes-matlab-to-crash-tp24163842p24163842.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net