Deadlock occuring in mutex code?

Another thread might obtain the lock between your while test and the swap.

Another thread might obtain the lock between your while test and the swap. You'd have to check the return of __sync_val_compare_and_swap and reiterate if it didn't succeed. Also your code for keeping track of the owner will not work, because in your unlock you may delete the information that some other thread has written.

Better you just have one field (handled with atomic operations) which holds the info on the owner and that is 0 if there is none.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions