BurritOS/test/syscall_tests/lock.c

30 lines
515 B
C
Raw Normal View History

#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;
}