root / trunk / code / projects / mapping / matlab / testMex / test.c @ 957
History | View | Annotate | Download (579 Bytes)
1 | 954 | justin | #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 | //deliberately ignore nrhs.
|
||
13 | if(nlhs != 1){ |
||
14 | mexErrMsgTxt("Error - only returns one number.\n");
|
||
15 | } |
||
16 | else{
|
||
17 | 957 | justin | |
18 | 954 | justin | if(first_time){
|
19 | 957 | justin | //Deploy a thread to count.
|
20 | 954 | justin | pthread_create(&counter, NULL, count, NULL); |
21 | } |
||
22 | |||
23 | 957 | justin | ret[0] = mxCreateDoubleMatrix(1, 1, mxREAL); |
24 | 954 | justin | double* value = mxGetPr(ret[0]); |
25 | *value = (double)global;
|
||
26 | } |
||
27 | } |
||
28 | |||
29 | void* count(void* arg){ |
||
30 | global++; |
||
31 | usleep(10000);
|
||
32 | } |