Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
I'm trying to get started with rtos and I didn't get very far trying to understand the mutex example. I understand the mutex concept, but I am having trouble with the thread creation and program output. It looks like all threads are outputting at once, but looking at the waits in test_thread I thought there would be a delay.
I was hoping someone could take the time to explain the basics of what is going on both with the thread creation and program execution.
Thanks,
Mike
#include "mbed.h" #include "rtos.h" Mutex stdio_mutex; void notify(const char* name, int state) { stdio_mutex.lock(); printf("%s: %d\n\r", name, state); stdio_mutex.unlock(); } void test_thread(void const *args) { while (true) { notify((const char*)args, 0); Thread::wait(1000); notify((const char*)args, 1); Thread::wait(1000); } } int main() { Thread t2(test_thread, (void *)"Th 2"); Thread t3(test_thread, (void *)"Th 3"); test_thread((void *)"Th 1"); }