amit ate
/
Wthread_mutex_blinky
Mutex Example
Fork of rtos_mutex by
main.cpp
- Committer:
- thinkfire
- Date:
- 2017-01-20
- Revision:
- 7:ff2e3fbefea7
- Parent:
- 6:1ae0d86d2020
File content as of revision 7:ff2e3fbefea7:
#include "mbed.h" #include "rtos.h" DigitalOut led1(LED1); DigitalOut led2(LED2); Mutex led_mutex; void delay(void){ for(int i=0;i<65000;i++){ for(int j=0;j<100;j++) { } } } void test_thread1(void const *args) { while (true) { led_mutex.lock(); printf("thd1 toogling\n"); led1 = !led1; delay(); led_mutex.unlock(); Thread::wait(1000); } } void test_thread2(void const *args) { while (true) { led_mutex.lock(); printf("thd2 toogling\n"); led1 = !led1; delay(); led_mutex.unlock(); Thread::wait(1000); } } void test_thread(void const *args) { while (true) { led_mutex.lock(); printf("main toogling\n"); led1 = !led1; delay(); led_mutex.unlock(); Thread::wait(1000); } } int main() { Thread t2(test_thread1, (void *)"Th 1"); Thread t3(test_thread2, (void *)"Th 2"); test_thread((void *)"main"); }