1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/projects/test_suite/mutex_trylock_fail.c

31 lines
689 B
C
Raw Normal View History

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
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...");
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.");
}