mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
test/sys_sched_round_robin: use sleep instead of mutex
to avoid priority-inversion screwing up the test
This commit is contained in:
parent
64b783b9fa
commit
2594032163
@ -19,17 +19,18 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "mutex.h"
|
|
||||||
|
|
||||||
static mutex_t _shared_mutex;
|
static kernel_pid_t main_pid;
|
||||||
|
|
||||||
void * thread_mutex_unlock(void *d)
|
|
||||||
|
void * thread_wakeup_main(void *d)
|
||||||
{
|
{
|
||||||
(void) d;
|
(void) d;
|
||||||
puts("mutex_thread yield");
|
puts("wakup_thread yield");
|
||||||
thread_yield();
|
thread_yield();
|
||||||
puts("unlock mutex");
|
while (puts("wakeup main"), thread_wakeup(main_pid) == (int)STATUS_NOT_FOUND) {
|
||||||
mutex_unlock(&_shared_mutex);
|
thread_yield();
|
||||||
|
};
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,26 +46,21 @@ void * thread_bad(void *d)
|
|||||||
/* each thread gets a stack */
|
/* each thread gets a stack */
|
||||||
static char stack[2][THREAD_STACKSIZE_DEFAULT];
|
static char stack[2][THREAD_STACKSIZE_DEFAULT];
|
||||||
|
|
||||||
/* with priority inversion this should be set to THREAD_PRIORITY_MAIN
|
/* shared priority of the threads - lower than main waiting for it to sleep */
|
||||||
* until then a lower priority (higher number) is the better choice */
|
static const uint8_t shared_prio = THREAD_PRIORITY_MAIN + 1;
|
||||||
const uint8_t shared_prio = THREAD_PRIORITY_MAIN + 1;
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
puts("starting threads");
|
puts("starting threads");
|
||||||
|
main_pid = thread_getpid();
|
||||||
mutex_init(&_shared_mutex);
|
|
||||||
thread_create(stack[0], sizeof(stack[0]), shared_prio, THREAD_CREATE_STACKTEST,
|
thread_create(stack[0], sizeof(stack[0]), shared_prio, THREAD_CREATE_STACKTEST,
|
||||||
thread_mutex_unlock, NULL, "TMutex");
|
thread_wakeup_main, NULL, "TWakeup");
|
||||||
thread_create(stack[1], sizeof(stack[1]), shared_prio, THREAD_CREATE_STACKTEST,
|
thread_create(stack[1], sizeof(stack[1]), shared_prio, THREAD_CREATE_STACKTEST,
|
||||||
thread_bad, NULL, "TBad");
|
thread_bad, NULL, "TBad");
|
||||||
|
puts("main is going to sleep");
|
||||||
|
thread_sleep();
|
||||||
|
|
||||||
puts("double locking mutex");
|
/* success: main got woken up again which means "TWakup" got cpu time
|
||||||
|
|
||||||
mutex_lock(&_shared_mutex);
|
|
||||||
mutex_lock(&_shared_mutex);
|
|
||||||
|
|
||||||
/* success: mutex got unlocked, which means thread "TMutex" got cpu time
|
|
||||||
* even though "TBad" was trying to hog the whole CPU */
|
* even though "TBad" was trying to hog the whole CPU */
|
||||||
puts("[SUCCESS]");
|
puts("[SUCCESS]");
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ from testrunner import run
|
|||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
child.expect_exact("starting threads")
|
child.expect_exact("starting threads")
|
||||||
child.expect_exact("double locking mutex")
|
child.expect_exact("main is going to sleep")
|
||||||
child.expect_exact("unlock mutex")
|
child.expect_exact("wakeup main")
|
||||||
child.expect_exact("[SUCCESS]")
|
child.expect_exact("[SUCCESS]")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user