Does mutex guarantee to execute thread in order of arriving?
that is, if, thread 2 and thread 3 arrive is waiting while thread 1 is in critical section
what exactly happen after thread 1 exit critical section if thread 2 arrive at mutex lock before thread 3, thread 2 will be allowed to enter critical section before thread 3 ?
or race condition will be occurred?
if its not guaranteed, how can i solve this? (maybe queue?)
That sort of behaviour would have to be an implementation detail of your threading library (which you didn’t mention). I would guess most threading libraries don’t make any such a guarantee, though. Unless the waiting threads had different priorities, of course.