Skip to content
Snippets Groups Projects
Commit 1083d0bb authored by David Nicolazo's avatar David Nicolazo :beers:
Browse files

mutex simple

parent 83e4ec2e
Branches
No related merge requests found
#include <stdio.h>
#include <pthread.h>
long int compteur = 0;
void *increment(void *arg)
{
for (size_t i = 0; i < 1000000; i++)
compteur++;
pthread_exit(NULL);
}
int main(void)
{
pthread_t threads[4];
for (size_t i = 0; i < 4; i++)
{
pthread_create(threads+i, NULL, increment, NULL);
}
for (size_t i = 0; i < 4; i++)
{
pthread_join(threads[i], NULL);
}
printf("%ld\n", compteur);
return 0;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment