Skip to content

Instantly share code, notes, and snippets.

@kkabdol
Created March 28, 2019 03:29
Show Gist options
  • Save kkabdol/b13abddc6785640693c040fb5fad04c7 to your computer and use it in GitHub Desktop.
Save kkabdol/b13abddc6785640693c040fb5fad04c7 to your computer and use it in GitHub Desktop.
Multithread (Review the last test)
#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