SEMAPHORE ADVANCE PART 4 EXAMPLE OF COUNTING SEMAPHORE IN MBED OS FOR PROTECTING CRITICAL SECTION OF SHARED RESOURCES TARGET BOARD NUCLEO - 64 OS PLATFORM : MBED CREATED BY : JAYDEEP SHAH -- radhey04ec@gmail.com
main.cpp
- Committer:
- radhey04ec
- Date:
- 2020-07-12
- Revision:
- 0:2de8a221f1d2
- Child:
- 1:d3e6b9a8a9c2
File content as of revision 0:2de8a221f1d2:
#include "mbed.h" #include "rtos.h" Semaphore two_slots(2); void test_thread(void const *name) { while (true) { two_slots.wait(); printf("%s\n\r", (const char*)name); //PRINT STRING AFTER TYPE CONVERSION Thread::wait(1000); //THREAD SLEEP FOR 1 SEC two_slots.release(); //SEMAPHORE RELEASE printf("AFTER SLEEP %s\n\r", (const char*)name); //AFTER SLEEP } } int main (void) { Thread t2; Thread t3; t2.start(callback(test_thread, (void *)"Th 2")); // CALL THE FUNCTION WITH CALLBACK COMMAND AND PASS STRING AS ARGUMENT t3.start(callback(test_thread, (void *)"Th 3")); test_thread((void *)"Th 1"); }