将请求的接口的动作放在互斥锁中进行
1:
2:
3: pthread_mutex_t mutex;
4: pthread_t thread;
5: sem_t * m_structSem;
6:
struct SimpleStructure
8: {
int data;
float otherData;
11: };
12:
void* arg)
14: {
15: pthread_mutex_lock(&mutex);
16: SimpleStructure* args = (SimpleStructure*)arg;
17:
//todo...
19:
delete args;
21: pthread_mutex_unlock(&mutex);
22:
23: pthread_mutex_destroy(&mutex);
24: sem_destroy(m_structSem);
25:
return NULL;
27: }
28:
29: pthread_mutex_init(&mutex, NULL);
30: m_structSem = sem_open(strThreadName.c_str(), O_CREAT, 0644, 0)
31:
//
new SimpleStructure();
34: args->data = 1;
35: args->otherData = 2.0f;
//
37: pthread_create(&thread, NULL, &ThreadFunction, args);
38:
39: