Skip to content

Instantly share code, notes, and snippets.

@benpicco
Created October 28, 2013 16:38
Show Gist options
  • Save benpicco/7200223 to your computer and use it in GitHub Desktop.
Save benpicco/7200223 to your computer and use it in GitHub Desktop.
second message is lost
#include <stdio.h>
#include "vtimer.h"
#include "thread.h"
#include "msg.h"
char timer_stack[KERNEL_CONF_STACKSIZE_DEFAULT];
struct timer_msg {
char* msg;
};
struct timer_msg msg_a = { .msg = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" };
struct timer_msg msg_b = { .msg = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" };
void timer_thread(void) {
printf("This is thread %d\n", thread_getpid());
while (1) {
msg_t m;
msg_receive(&m);
struct timer_msg* tmsg = (struct timer_msg*) m.content.ptr;
puts(tmsg->msg);
/* allow switching to main thread for next msg to be sent */
vtimer_usleep(1000);
}
}
int main(void) {
msg_t m;
int pid = thread_create(timer_stack, sizeof timer_stack, PRIORITY_MAIN-1, CREATE_STACKTEST, timer_thread, "timer");
puts("sending 1st msg");
m.content.ptr = (char*) &msg_a;
msg_send(&m, pid, false);
puts("sending 2nd msg");
m.content.ptr = (char*) &msg_b;
msg_send(&m, pid, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment