Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Conflito entre 4 threads
#include <stdio.h> #include <stdlib.h> #include <pthread.h> int variavelGlobal; void* incrementar() { int temp = variavelGlobal; for (int i = 0; i < 10000; i++); variavelGlobal = temp + 1; return 0; } void* decrementar() { int temp = variavelGlobal; for (int i = 0; i < 10000; i++); variavelGlobal = temp - 1; return 0; } int main() { pthread_t threadA, threadB, threadC, threadD; for (int x = 0; x < 10; x++) { variavelGlobal = 10; pthread_create(&threadA, NULL, incrementar, NULL); pthread_create(&threadB, NULL, decrementar, NULL); pthread_create(&threadC, NULL, incrementar, NULL); pthread_create(&threadD, NULL, decrementar, NULL); pthread_join(threadA, NULL); pthread_join(threadB, NULL); pthread_join(threadC, NULL); pthread_join(threadD, NULL); printf("Resultado: %d\n", variavelGlobal); } return 0; }
run
|
edit
|
history
|
help
0
Lp
Encriptado cesar
Lior Yehieli Lesson
printing float 2 pointers
Busqueda binaria version recursiva
lab2
A_141205_Palindromo
Assignment 3
time clock and day count through second by user input (ratneshgujarathi)
finalpyramid