Revision 954
Just some test code to see how concurrency works in matlab functions.
trunk/code/projects/mapping/matlab/testMex/test.c | ||
---|---|---|
1 |
#include <mex.h> |
|
2 |
#include <unistd.h> |
|
3 |
|
|
4 |
pthread_t counter; |
|
5 |
|
|
6 |
void* count(void* arg); |
|
7 |
int first_time = 0, global = 0; |
|
8 |
|
|
9 |
void mexFunction(int nlhs, |
|
10 |
mxArray* ret[], int nrhs, const mxArray* args[]) |
|
11 |
{ |
|
12 |
Return stuff to matlab |
|
13 |
//deliberately ignore nrhs. |
|
14 |
if(nlhs != 1){ |
|
15 |
mexErrMsgTxt("Error - only returns one number.\n"); |
|
16 |
} |
|
17 |
else{ |
|
18 |
if(first_time){ |
|
19 |
pthread_create(&counter, NULL, count, NULL); |
|
20 |
} |
|
21 |
//Deploy a thread to count. |
|
22 |
|
|
23 |
ret[0] = mxCreateDoubleMatrix(num_buffer_elements, 2, mxREAL); |
|
24 |
double* value = mxGetPr(ret[0]); |
|
25 |
*value = (double)global; |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
void* count(void* arg){ |
|
30 |
global++; |
|
31 |
usleep(10000); |
|
32 |
} |
Also available in: Unified diff