Created
September 26, 2012 23:51
-
-
Save guilherme/3791364 to your computer and use it in GitHub Desktop.
pthread_mutex
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 <pthread.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <sys/types.h> | |
#include <sys/ipc.h> | |
#include <sys/sem.h> | |
void funcao1(int *id); | |
void funcao2(int *id); | |
int x=10; | |
int i; | |
pthread_mutex_t lock; | |
int main() | |
{ | |
system("clear"); | |
pthread_t thread1; | |
pthread_t thread2; | |
int id_thread1; | |
int id_thread2; | |
id_thread1 = 1; | |
id_thread2 = 2; | |
pthread_create(&thread1,NULL,(void* )funcao1,&id_thread1); | |
pthread_create(&thread2,NULL,(void* )funcao2,&id_thread2); | |
pthread_join(thread1,NULL); | |
pthread_join(thread1,NULL); | |
} | |
void funcao1(int *id) | |
{ | |
printf("PAI RODANDO...\n"); | |
} | |
void funcao2(int *id) | |
{ | |
pthread_mutex_lock(&lock); | |
for(i=0;i<x;i++) | |
{ | |
printf("filho processando...\n"); | |
} | |
pthread_mutex_unlock(&lock); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment