burritos/test/syscall_tests/lock.c
2023-05-10 12:51:12 +02:00

30 lines
515 B
C

#include "userlib/syscall.h"
#include "userlib/libnachos.h"
LockId mutex;
int glob_int = 0;
void increment(void){
LockAcquire(mutex);
glob_int++;
LockRelease(mutex);
}
void counter(int n){
for (int i = 0; i < 50; i++){
increment();
}
}
int main(void){
mutex = LockCreate("Lock_debug");
ThreadId th1 = threadCreate("Thread1", (VoidNoArgFunctionPtr) counter);
ThreadId th2 = threadCreate("Thread2",(VoidNoArgFunctionPtr) counter);
Join(th1);
Join(th2);
Exit(glob_int);
return 0;
}