Added simple threading example with callbacks from Thread.h in mbed-os 5.3.2

Files at this revision

API Documentation at this revision

Comitter:
mab5449
Date:
Thu Jan 12 23:54:51 2017 +0000
Commit message:
Initiala commit. Simple RTOS threading example in mbed 5.3 using the Callback API

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 12 23:54:51 2017 +0000
@@ -0,0 +1,21 @@
+#include "mbed.h"
+
+Thread thread;
+DigitalOut led1(LED1);
+volatile bool running = true;
+
+// Blink function toggles the led in a long running loop
+void blink(DigitalOut *led) {
+    while (running) {
+        *led = !*led;
+        wait(1);
+    }
+}
+
+// Spawns a thread to run blink for 5 seconds
+int main() {
+    thread.start(callback(blink, &led1));
+    wait(5);
+    running = false;
+    thread.join();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Jan 12 23:54:51 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#2885c1b41e63158cb6faf5f107cd821ae06ef26c