Hi ;
My question is related to MUTEX
- I am using trylock_for() and trylock_until() function to protect my critical section. But after sometime my MBED os crash !!! why ??? I have attached image of terminal for more information.
- I cant understand how these function work. according to me when first thread enter in to critical section at that time MUTEX flag set for time mentioned in function bracket. After time elapsed mutex automatically unlock that . so next thread can enter into block. Am I right ???
But when next thread (suppose T2) enter at same time all other threads (which are standing at door) also enter in my critical section. Why ? why second thread not set mutex lock for other ?
I attached my code here :
<>
#include “mbed.h”
Mutex Lock;
Thread T1,T2;
void common_block(const char *name,int state)
{
printf(“\n This %s Thread arrive at door with state %d \n”,name,state);
Lock.trylock_until(1); //lock for 3000 ms
printf(“\n Inside the door %s with state %d \n”,name,state);
wait(02); //some how process stuck in wait state
printf(“\n Thread %s is Ouside wait period with state %d \n”,name,state);
}
void fun(void const *arg)
{
while(true)
{
common_block((const char *)arg,0); //PASS STATE 0
wait(2);
common_block((const char *)arg,1);// PASS STATE 1
wait(3);
}
}
int main()
{
T1.start(callback(fun,(void *)“T1”));
T2.start(callback(fun,(void *)“T2”));
fun((void *)“main”);
}
<>
Why ??? OS crashed not immediately ???
