Random Delay With Thread

Dependencies:   mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
thinkfire
Date:
Fri Jan 20 11:52:20 2017 +0000
Commit message:
tested

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r be029d41beb4 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jan 20 11:52:20 2017 +0000
@@ -0,0 +1,48 @@
+#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) {
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r be029d41beb4 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Jan 20 11:52:20 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r be029d41beb4 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jan 20 11:52:20 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file