diff --git a/sys/kern/syscall.c b/sys/kern/syscall.c index a0b4d21..fb42f96 100644 --- a/sys/kern/syscall.c +++ b/sys/kern/syscall.c @@ -440,7 +440,7 @@ Syscall_ThreadSleep(uint64_t time) uint64_t Syscall_ThreadWait(uint64_t tid) { - int status; + uint64_t status; Thread *cur = Sched_Current(); /* diff --git a/tests/pthreadtest.c b/tests/pthreadtest.c index 0cdc81c..e931279 100644 --- a/tests/pthreadtest.c +++ b/tests/pthreadtest.c @@ -5,8 +5,8 @@ #include #include -#include -#include + +pthread_mutex_t mtx; void * thread_simple(void *arg) @@ -16,9 +16,27 @@ thread_simple(void *arg) return arg; } +void * +thread_lock(void *arg) +{ + int i; + int status; + + for (i = 0; i < 100; i++) { + status = pthread_mutex_lock(&mtx); + assert(status == 0); + pthread_yield(); + status = pthread_mutex_unlock(&mtx); + assert(status == 0); + } + + return NULL; +} + int main(int argc, const char *argv[]) { + int i; int status; pthread_t thr; void *result; @@ -42,6 +60,32 @@ main(int argc, const char *argv[]) assert(result == (void *)1); // Mutex test + printf("simple mutex lock test\n"); + status = pthread_mutex_init(&mtx, NULL); + assert(status == 0); + status = pthread_mutex_lock(&mtx); + assert(status == 0); + status = pthread_mutex_unlock(&mtx); + assert(status == 0); + status = pthread_mutex_destroy(&mtx); + assert(status == 0); + + // Mutex Contention Test + printf("contended mutex lock test\n"); + pthread_mutex_init(&mtx, NULL); + status = pthread_create(&thr, NULL, thread_simple, (void *)1); + assert(status == 0); + for (i = 0; i < 100; i++) { + status = pthread_mutex_lock(&mtx); + assert(status == 0); + pthread_yield(); + pthread_mutex_unlock(&mtx); + assert(status == 0); + } + status = pthread_join(thr, &result); + assert(status == 0); + status = pthread_mutex_destroy(&mtx); + assert(status == 0); printf("Success!\n");