Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Deadlock
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <pthread.h> int qualquer_coisa; pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; void* incrementar(void* num) { int i; pthread_mutex_lock(&mutex1); for(i = 0; i < 999999999; i++); pthread_mutex_lock(&mutex2); qualquer_coisa++; pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex1); return 0; } void* decrementar(void* num) { int i; pthread_mutex_lock(&mutex2); for(i = 0; i < 999999999; i++); pthread_mutex_lock(&mutex1); qualquer_coisa--; pthread_mutex_unlock(&mutex1); pthread_mutex_unlock(&mutex2); return 0; } int main() { int num_th1, num_th2; pthread_t th1, th2; qualquer_coisa = 10; pthread_create(&th1, NULL, incrementar, (void*) &num_th1); pthread_create(&th2, NULL, decrementar, (void*) &num_th2); pthread_join(th1, NULL); pthread_join(th2, NULL); printf("Resultado %d\n", qualquer_coisa); return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
C_141106_Potencia
NO OF NODES IN LINK LIST
Practica 5 ejercicio beneficio empresa
Welcome1
tickeParsing.c
hello kous
Project v0.07
MergeSort
Threads_posix
Area of the Cone
Please log in to post a comment.