2014-01-10 16:21:35 +01:00
|
|
|
/*
|
2014-01-27 20:43:54 +01:00
|
|
|
* Copyright (C) 2013 Christian Mehlis <mehlis@inf.fu-berlin.de>
|
2014-01-10 16:21:35 +01:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-01-10 16:21:35 +01:00
|
|
|
*/
|
|
|
|
|
2014-02-03 23:03:13 +01:00
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Thread test application
|
|
|
|
*
|
|
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2014-01-10 16:21:35 +01:00
|
|
|
#include <stdio.h>
|
2014-05-07 00:06:18 +02:00
|
|
|
#include <inttypes.h>
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
|
|
|
|
2015-04-28 20:02:05 +02:00
|
|
|
char t1_stack[THREAD_STACKSIZE_MAIN];
|
|
|
|
char t2_stack[THREAD_STACKSIZE_MAIN];
|
|
|
|
char t3_stack[THREAD_STACKSIZE_MAIN];
|
2014-01-10 16:21:35 +01:00
|
|
|
|
2017-10-25 15:06:48 +02:00
|
|
|
kernel_pid_t p_main, p1, p2, p3;
|
2014-01-10 16:21:35 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
void *thread1(void *arg)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
2014-01-10 16:21:35 +01:00
|
|
|
puts("THREAD 1 start\n");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
msg_t msg, reply;
|
|
|
|
|
|
|
|
msg_receive(&msg);
|
2014-05-02 14:28:41 +02:00
|
|
|
printf("T1 recv: %" PRIu32 "(i=%d)\n", msg.content.value, i);
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
msg.content.value = i;
|
|
|
|
msg_send_receive(&msg, &reply, p2);
|
2014-05-02 14:28:41 +02:00
|
|
|
printf("T1 got reply: %" PRIu32 " (i=%d)\n", reply.content.value, i);
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
puts("THREAD 1 end\n");
|
2017-10-25 15:06:48 +02:00
|
|
|
msg_t msg;
|
|
|
|
msg_send(&msg, p_main);
|
2014-03-04 20:20:01 +01:00
|
|
|
return NULL;
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
void *thread2(void *arg)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
2017-10-25 15:06:48 +02:00
|
|
|
puts("THREAD 2 start\n");
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
for (int i = 0;; ++i) {
|
|
|
|
msg_t msg, reply;
|
|
|
|
|
|
|
|
msg_receive(&msg);
|
2014-05-02 14:28:41 +02:00
|
|
|
printf("T2 got %" PRIu32 " (i=%d)\n", msg.content.value, i);
|
2014-01-10 16:21:35 +01:00
|
|
|
reply.content.value = msg.content.value;
|
|
|
|
msg_reply(&msg, &reply);
|
|
|
|
}
|
2014-03-04 20:20:01 +01:00
|
|
|
|
|
|
|
return NULL;
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
void *thread3(void *arg)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
2017-10-25 15:06:48 +02:00
|
|
|
puts("THREAD 3 start\n");
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
for (int i = 0;; ++i) {
|
|
|
|
msg_t msg;
|
|
|
|
msg.content.value = i;
|
|
|
|
printf("T3 i=%d\n", i);
|
2014-10-20 16:49:40 +02:00
|
|
|
msg_send(&msg, p1);
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
2014-03-04 20:20:01 +01:00
|
|
|
return NULL;
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2020-08-23 21:28:33 +02:00
|
|
|
p_main = thread_getpid();
|
2015-04-28 20:02:05 +02:00
|
|
|
p1 = thread_create(t1_stack, sizeof(t1_stack), THREAD_PRIORITY_MAIN - 1,
|
2015-12-02 12:00:37 +01:00
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
2014-03-04 20:20:01 +01:00
|
|
|
thread1, NULL, "nr1");
|
2015-04-28 20:02:05 +02:00
|
|
|
p2 = thread_create(t2_stack, sizeof(t2_stack), THREAD_PRIORITY_MAIN - 1,
|
2015-12-02 12:00:37 +01:00
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
2014-03-04 20:20:01 +01:00
|
|
|
thread2, NULL, "nr2");
|
2015-04-28 20:02:05 +02:00
|
|
|
p3 = thread_create(t3_stack, sizeof(t3_stack), THREAD_PRIORITY_MAIN - 1,
|
2015-12-02 12:00:37 +01:00
|
|
|
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
2014-03-04 20:20:01 +01:00
|
|
|
thread3, NULL, "nr3");
|
2014-01-10 16:21:35 +01:00
|
|
|
puts("THREADS CREATED\n");
|
2017-10-25 15:06:48 +02:00
|
|
|
|
|
|
|
msg_t msg;
|
|
|
|
/* Wait until thread 1 is done */
|
|
|
|
msg_receive(&msg);
|
|
|
|
|
|
|
|
puts("SUCCESS");
|
|
|
|
|
2014-06-20 20:00:20 +02:00
|
|
|
return 0;
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|