Skip to content

Instantly share code, notes, and snippets.

@UndeRus
Created March 22, 2011 21:24
Show Gist options
  • Save UndeRus/882108 to your computer and use it in GitHub Desktop.
Save UndeRus/882108 to your computer and use it in GitHub Desktop.
#include <pthread.h>
#include <stdio.h>
int count = 100;
pthread_mutex_t mutex;
void* adder( void *counter){
int tid, cnt;
/* tid = (int)threadid; */
cnt = (int)counter;
pthread_mutex_lock(&mutex);
*cnt += 1;
pthread_mutex_unlock(&mutex);
printf ("Hellowordule %i\n", tid);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[6];
int rc;
long t;
for (t = 0; t < 6; t++)
{
rc = pthread_create(&threads[t], NULL, adder, (void*)(&count));
}
printf ("%i\n", count);
pthread_exit(NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment