Created
March 28, 2019 03:29
-
-
Save kkabdol/b13abddc6785640693c040fb5fad04c7 to your computer and use it in GitHub Desktop.
Multithread (Review the last test)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cassert> | |
#include <pthread.h> | |
using namespace std; | |
int g_Count = 0; | |
void *thread( void *vargp ) | |
{ | |
for( int i = 0; i < 1000; ++i ) | |
{ | |
++g_Count; | |
} | |
} | |
int main() | |
{ | |
pthread_t tid, tid2; | |
pthread_create( &tid, NULL, thread, NULL ); | |
pthread_create( &tid2, NULL, thread, NULL ); | |
pthread_join( tid, NULL ); | |
pthread_join( tid2, NULL ); | |
cout << g_Count << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment