j'ai essayé de compiler le code suivant :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <pthread.h> /* for threading */
#include <unistd.h> /* for sleep */
#include <windows.h>
#include <process.h>
#include "mex.h"
#include "matrix.h"
void *do_thread(void *threadid)
{
int tid;
tid = (int)threadid;
mexPrintf("In thread: just started thread #%dn", tid);
sleep(4); /* pretend that the code is busy for a few seconds */
mexPrintf("In thread: about to exit from thread #%dn", tid);
pthread_exit(NULL);
return NULL;
}
void mexFunction (int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
int num, rc, t;;
if (nrhs<1)
mexErrMsgTxt("not enough input arguments");
else
num = mxGetScalar(prhs[0]);
pthread_t threads[num];
for(t=0; t < num ; t++)
{
mexPrintf("In main: creating thread %dn", t);
rc = pthread_create(&threads[t], NULL, do_thread, (void *)t);
if (rc)
{
mexErrMsgTxt("problem with return code from pthread_create()");
}
sleep(1); /* wait some time before making the next thread */
} return;
} |
mais matlab me donnee des erreurs :
>> mex Thread.c -lpthread
lcc preprocessor error: Thread.c:1 Could not find include file <pthread.h>
lcc preprocessor error: Thread.c:2 Could not find include file <unistd.h>
lcc preprocessor warning: Thread.c:37 No newline at end of file
Error Thread.c: 26 undeclared identifier `pthread_t'
Warning Thread.c: 26 Statement has no effect
Error Thread.c: 26 syntax error; found `threads' expecting `;'
Error Thread.c: 26 undeclared identifier `threads'
Error Thread.c: 26 type error: pointer expected
Warning Thread.c: 26 Statement has no effect
Error Thread.c: 30 type error: pointer expected
Warning Thread.c: 26 possible usage of threads before definition
Warning Thread.c: 26 possible usage of pthread_t before definition
7 errors, 5 warnings
Partager