Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / mapping / matlab / testMex / test.c @ 957

History | View | Annotate | Download (579 Bytes)

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
        //deliberately ignore nrhs.        
13
        if(nlhs != 1){
14
                mexErrMsgTxt("Error - only returns one number.\n");
15
        }
16
        else{
17
                
18
                if(first_time){
19
                        //Deploy a thread to count.
20
                        pthread_create(&counter, NULL, count, NULL);
21
                }
22

    
23
                ret[0] = mxCreateDoubleMatrix(1, 1, 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
}