Jaydeep Shah
/
21_MUTEX_LOCK_UNLOCK
MUTEX and its use in MBED MUTEX LOCK and Unlock mechanism
Diff: main.cpp
- Revision:
- 1:605f5624661e
- Parent:
- 0:b908013d70cd
- Child:
- 2:0cf7e435eeb8
--- a/main.cpp Sat Jul 25 09:46:26 2020 +0000 +++ b/main.cpp Sun Jul 26 10:59:21 2020 +0000 @@ -1,9 +1,8 @@ -/* 21_ MUTEX a Guard at door - Basic program (All thread with same priority level) +/* 21_ MUTEX a Guard at door - Basic program MUTEX allow only one Thread / Function call inside CS, Mutex have ownership type locking mechanism. Procees /or Thread who locked block,only same process /or thread can unlock it. */ -//BUGS in MUTEX CLASS -//NOTE : MUTEX ONLY PROTECT CS from processes which are belonging same priority level -MBED BUG + //PROGRAM CREATED BY : JAYDEEP SHAH -- radheec@gmail.com //DATE : 25 JULY 20 ,VERSION 1.0 @@ -17,9 +16,9 @@ //Create Two Thread -Thread t2; //Create Thread with high priority +Thread t2; -Thread t3; //Create Thread with low priority +Thread t3; //Here below section act as CS critical section @@ -32,9 +31,12 @@ printf("This Thread lock the code %s: %d\n\r", name, state); wait(0.5); //sleep + printf("Thread cross & unlock %s: %d\n\r", name, state); //OUTSIDE CODE BLOCK --------- + M_LOCK.unlock(); //After completing task unlock the code ------------- UNLOCK THE BLOCK - printf("Thread cross & unlock %s: %d\n\r", name, state); //OUTSIDE CODE BLOCK --------- +//DO NOT WRITE any print statement after unlock() it create missunderstanding .... +/* print statement require more clk cycle,after unlock the MUTEX Flag - schedular quickly schedule next thread before print the statement.*/ }