forked from Rativel/BurritOS
remplacement du lecteur rédacteur par les lock
This commit is contained in:
29
test/syscall_tests/lock.c
Normal file
29
test/syscall_tests/lock.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user