All very logical steps, and steps which I'm sure I tried at some point ;)
Firstly, the posix threads solution works just fine, I've included the
program I tested (a slight modification of a standard example program).
/*
* p_hello.c -- a hello program (in pthread)
*/
#include "mex.h"
#include
#include
#include
#define MAX_THREAD 1000
typedef struct {
int id;
} parm;
void *hello(void *arg)
{
parm *p=(parm *)arg;
printf("Hello from node %d\n", p->id);
return (NULL);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int n,i;
pthread_t *threads;
pthread_attr_t pthread_custom_attr;
parm *p;
n=3;
if ((n < 1) || (n > MAX_THREAD))
{
printf ("The no of thread should between 1 and
%d.\n",MAX_THREAD);
exit(1);
}
threads=(pthread_t *)malloc(n*sizeof(*threads));
pthread_attr_init(&pthread_custom_attr);
p=(parm *)malloc(sizeof(parm)*n);
/* Start up thread */
for (i=0; i () from
/usr/lib/libboost_thread-gcc41-mt-1_38.so.1.38.0
#2 0x0260beda in boost::detail::set_current_thread_data () from
/usr/lib/libboost_thread-gcc41-mt-1_38.so.1.38.0
#3 0x0260cff3 in thread_proxy () from
/usr/lib/libboost_thread-gcc41-mt-1_38.so.1.38.0
#4 0x0067049b in start_thread () from /lib/libpthread.so.0
#5 0x005c742e in clone () from /lib/libc.so.6
Just for fun I wrote another program to see if the problem was anything to
do with boost mutexes or conditions (without using other threads), and
matlab has no issues with this.
--
View this message in context: http://www.nabble.com/Creating-a-boost-thread-in-a-matlab-mex-file-causes-ma...
Sent from the Boost - Users mailing list archive at Nabble.com.