Created
May 10, 2016 18:31
-
-
Save coypoop/49dc9aa86999e108b5f82f61cf6c2159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/param.h> | |
#include <sys/kernel.h> | |
#include <sys/kthread.h> | |
#define NTHREADS 4 | |
#define MAX_ITERATIONS 5000 | |
static volatile int elements[NTHREADS] = {0}; | |
void | |
main() | |
{ | |
lwp_t **l; | |
int i; | |
for (i = 0; i < NTHREADS; ++i) { | |
error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, i, | |
thread_run, i, &l[i], "kernellocktest"); | |
KASSERT(error == 0); | |
} | |
} | |
void | |
thread_run(unsigned thread_no) | |
{ | |
int i; | |
int j; | |
for (j = 0; j < MAX_ITERATIONS; ++j) { | |
KERNEL_LOCK(1, NULL); | |
elements[thread_no] = 1; | |
for (i = 0; i < NTHREADS; ++i) { | |
if (i != thread_no) | |
KASSERTMSG(elements[i] == 0, | |
"the impossible has happened"); | |
} | |
elements[thread_no] = 0; | |
KERNEL_UNLOCK_ONE(NULL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment