amit ate
/
Wthread_random_delay
Random Delay With Thread
main.cpp
- Committer:
- thinkfire
- Date:
- 2017-01-20
- Revision:
- 0:be029d41beb4
File content as of revision 0:be029d41beb4:
#include "mbed.h" #include "rtos.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); void led1_thread(void const *args) { while (true) { led1 = !led1; Thread::wait((rand()%700)+1); } } void led2_thread(void const *args) { while (true) { led2 = !led2; Thread::wait((rand()%700)+1); } } void led3_thread(void const *args) { while (true) { led3 = !led3; Thread::wait((rand()%700)+1); } } void led4_thread(void const *args) { while (true) { led4 = !led4; Thread::wait((rand()%700)+1); } } int main() { //Create a thread to execute the function led2_thread Thread thread1(led1_thread); Thread thread2(led2_thread); Thread thread3(led3_thread); Thread thread4(led4_thread); //led2_thread is executing concurrently with main at this point while (true) { } }