2010-11-01 16:12:22 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <mutex.h>
|
|
|
|
|
|
|
|
#include <thread.h>
|
|
|
|
#include <flags.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
|
|
|
|
mutex_t mutex;
|
|
|
|
|
2010-11-02 11:52:39 +01:00
|
|
|
static void second_thread(void) {
|
2010-11-01 16:12:22 +01:00
|
|
|
puts(" 2nd: trying to lock mutex...");
|
|
|
|
mutex_trylock(&mutex);
|
|
|
|
puts(" 2nd: done.");
|
|
|
|
}
|
|
|
|
|
2010-11-02 11:52:39 +01:00
|
|
|
static char second_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
2010-11-01 16:12:22 +01:00
|
|
|
|
2010-11-01 17:05:00 +01:00
|
|
|
void mutex_trylock_fail(char* cmdline)
|
2010-11-01 16:12:22 +01:00
|
|
|
{
|
|
|
|
puts("main: locking mutex...");
|
|
|
|
mutex_lock(&mutex);
|
|
|
|
|
|
|
|
puts("main: creating thread...");
|
2010-11-04 16:47:24 +01:00
|
|
|
thread_create(second_stack, KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2");
|
2010-11-01 16:12:22 +01:00
|
|
|
|
|
|
|
puts("main: thread created. Unlocking mutex...");
|
|
|
|
mutex_unlock(&mutex, true);
|
|
|
|
|
|
|
|
puts("main: mutex unlocked.");
|
|
|
|
}
|