finished

Dependencies:   mbed-rtos mbed

Fork of rtos_mutex by mbed official

Revision:
5:969aeadd077e
Parent:
1:0f886ffbe0c1
--- a/main.cpp	Tue Jun 04 16:03:01 2013 +0100
+++ b/main.cpp	Fri Feb 13 00:03:22 2015 +0000
@@ -1,24 +1,26 @@
-#include "mbed.h"
-#include "rtos.h"
+#include "mbed.h"                                           //Include the mbed.h file
+#include "rtos.h"                                           //Include the rtos.h file
 
-Mutex stdio_mutex; 
+Mutex stdio_mutex;                                          //Setup the mutex
 
-void notify(const char* name, int state) {
-    stdio_mutex.lock();
-    printf("%s: %d\n\r", name, state);
-    stdio_mutex.unlock();
+void notify(const char* name, int state) {                  //function and passes data NAME and STATE to the function
+    stdio_mutex.lock();                                     //mutex lock stdio_mutex 
+    printf("%s: %d\n\r", name, state);                      //read name and state and print them on serial
+    stdio_mutex.unlock();                                   //mutex unlock stdio_mutex 
 }
 
-void test_thread(void const *args) {
-    while (true) {
-        notify((const char*)args, 0); Thread::wait(1000);
-        notify((const char*)args, 1); Thread::wait(1000);
-    }
-}
+void test_thread(void const *args) {                        //Thread and function, pass data to the thread/function
+    while (true) {                                          //Super loop
+        notify((const char*)args, 0);                       //function call, passes number and toggles data to the function
+        Thread::wait(1000);                                 //Thread wait 1 sec
+        notify((const char*)args, 1);                       ////function call, pass two data to the function
+        Thread::wait(1000);                                 //Thread wait 1 sec
+    }                                                       //end super loop
+}                                                           //end function
 
 int main() {
-    Thread t2(test_thread, (void *)"Th 2");
-    Thread t3(test_thread, (void *)"Th 3");
+    Thread t2(test_thread, (void *)"Th 2");                 //start thread t2
+    Thread t3(test_thread, (void *)"Th 3");                 //start thread t3
     
-    test_thread((void *)"Th 1");
-}
+    test_thread((void *)"Th 1");                            //function call
+}                                                           //end main