2014-02-12 16:58:05 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
|
|
|
*
|
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-02-12 16:58:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Thread test application
|
|
|
|
*
|
|
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
|
|
|
* @author Lotte Steenbrink <lotte.steenbrink@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
|
|
|
|
2015-04-28 20:02:05 +02:00
|
|
|
char t1_stack[THREAD_STACKSIZE_MAIN];
|
2014-02-12 16:58:05 +01:00
|
|
|
|
2014-08-06 09:44:31 +02:00
|
|
|
kernel_pid_t p1 = KERNEL_PID_UNDEF, p_main = KERNEL_PID_UNDEF;
|
2014-02-12 16:58:05 +01:00
|
|
|
|
2014-03-04 20:20:01 +01:00
|
|
|
void *thread1(void *arg)
|
2014-02-12 16:58:05 +01:00
|
|
|
{
|
2014-03-04 20:20:01 +01:00
|
|
|
(void) arg;
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("THREAD %" PRIkernel_pid " start\n", p1);
|
2014-02-12 16:58:05 +01:00
|
|
|
|
|
|
|
msg_t msg, reply;
|
|
|
|
memset(&msg, 1, sizeof(msg_t));
|
|
|
|
|
|
|
|
/* step 1: send asynchonously */
|
2014-10-20 16:49:40 +02:00
|
|
|
msg_try_send(&msg, p_main);
|
2014-02-12 16:58:05 +01:00
|
|
|
|
|
|
|
/* step 2: send message, turning its status into STATUS_REPLY_BLOCKED */
|
|
|
|
msg_send_receive(&msg, &reply, p_main);
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("received: %" PRIkernel_pid ", %u \n", reply.sender_pid, reply.type);
|
2014-02-12 16:58:05 +01:00
|
|
|
printf("pointer: %s\n", reply.content.ptr);
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("THREAD %" PRIkernel_pid " SHOULD BE BLOCKING :(\n", p1);
|
2014-03-04 20:20:01 +01:00
|
|
|
|
|
|
|
return NULL;
|
2014-02-12 16:58:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
msg_t msg;
|
2014-04-10 22:28:35 +02:00
|
|
|
p_main = sched_active_pid;
|
2014-02-12 16:58:05 +01:00
|
|
|
|
|
|
|
msg_t msg_q[1];
|
|
|
|
msg_init_queue(msg_q, 1);
|
|
|
|
|
2015-04-28 20:02:05 +02:00
|
|
|
p1 = thread_create(t1_stack, sizeof(t1_stack), THREAD_PRIORITY_MAIN - 1,
|
2014-03-04 20:20:01 +01:00
|
|
|
CREATE_WOUT_YIELD | CREATE_STACKTEST,
|
|
|
|
thread1, NULL, "nr1");
|
2014-02-12 16:58:05 +01:00
|
|
|
|
|
|
|
/* step 3: receive a msg */
|
|
|
|
msg_receive(&msg);
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
printf("MAIN THREAD %" PRIkernel_pid " ALIVE!\n", p_main);
|
2014-06-20 20:00:20 +02:00
|
|
|
return 0;
|
2014-02-12 16:58:05 +01:00
|
|
|
}
|