Solution using TestAndSet to solve critical section problem

https://code.sololearn.com/cTwgO21bkXwK/?ref=app I am using TestAndSet in this code to solve critical section problem, but doesn't work. Help me please.

15th Apr 2021, 10:56 AM
hanan alhinai
hanan alhinai - avatar
1 Réponse
Your function showing some errors check your line 16 TestAndSet fix it also Some errors i have removed #include <stdio.h> #include <stdlib.h> #include <pthread.h> long long sum=0,num=40000000; void *mySumFun(void *vargp){ int step=*(int *) vargp; for(int i=0;i<num;i++){ TestAndSet(&clock); sum+=step; clock=fclose; } return NULL; } int main() { pthread_t tid1,tid2; int step1=1,step2=-1; pthread_create(&tid2, NULL, mySumFun, &step2); pthread_create(&tid1, NULL, mySumFun, &step1); pthread_join(tid1, NULL); pthread_join(tid2, NULL); printf("The sum is = %lld \n" , sum); exit(0); }
15th Apr 2021, 12:59 PM
A S Raghuvanshi
A S Raghuvanshi - avatar