-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (40 loc) · 990 Bytes
/
main.cpp
File metadata and controls
44 lines (40 loc) · 990 Bytes
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
38
39
40
41
42
43
44
#include "fmatch.h"
#include <time.h>
#include <pthread.h>
void *getMatch(void *iMatch)
{
int ii=0, iMid = *(int*)iMatch;
cout<<"Get Match "<<iMid<<endl;
fmatch m(iMid);
if (!m.getData()) return NULL;
cout<<"Loop "<<ii++<<endl;
while (m.status<4)
{
cout<<"Loop "<<ii++<<endl;
m.getData();
sleep(3);
}
cout<<"Endof getmatch "<<iMid<<endl;
}
void test_thread()
{
pthread_t thread1, thread2;
int iret1, iret2;
int m1=349361, m2=349360;
printf("Create Threads\n");
iret1 = pthread_create( &thread1, NULL, getMatch, &m1);
pthread_join( thread1, NULL);
iret2 = pthread_create( &thread1, NULL, getMatch, &m2);
pthread_join( thread1, NULL);
printf("Thread 1 returns: %d\n",iret1);
printf("Thread 2 returns: %d\n",iret2);
}
int main(int argc, char** argv)
{
//database db;
//int database::c=1;
//int m1=349361, m2=349360;
//getMatch(&m1);
test_thread();
return 0;
}