
MUTEX _TIME BASED LOCK UNLOCK SYSTEM to avoid priority inversion and deadlock or thread stuck issue.
Revision 1:4f150e2895bf, committed 2020-07-26
- Comitter:
- radhey04ec
- Date:
- Sun Jul 26 13:18:27 2020 +0000
- Parent:
- 0:f8e6d9529dbd
- Commit message:
- FINAL COMMIT
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Jul 26 13:15:49 2020 +0000 +++ b/main.cpp Sun Jul 26 13:18:27 2020 +0000 @@ -28,7 +28,7 @@ void common_block(const char* name, int state) { printf("\n Thread arrive %s %d \n", name, state); - if (Lock.trylock_for(50)) { // try to lock the mutex: timeout = 100 ms + if (Lock.trylock_for(50)) { // try to lock the mutex: timeout = 50 ms----------------------------- printf("\n Inside %s state %d \n", name, state); ThisThread::sleep_for(6000); //some how process stuck in wait state printf("\n outside %s state %d \n", name, state); @@ -36,7 +36,8 @@ } else { - + //Thread back to other work/next process if fail to acquire Critical section + //Thread not stuck for getting mutex flag it can do other important work also printf("\n %s thread fail to lock state %d",name,state); } }