[nanomsg] Re: Lock in nn_sock_send

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: Steven Wu <stevenwu.ucd@xxxxxxxxx>
  • Date: Thu, 19 Sep 2013 09:35:07 +0200

On 16/09/13 18:34, Steven Wu wrote:

Yes, your scenario will be dead lock. However, if the shared mutex will
be unlocked at first before locking the connection wise lock due to they
are at different stage in the logic, hence a thread should never lock
both at the same time.

Consider this scenario:

1. User sends a message.
2. Shared mutex is locked.
3. A connection is chosen for sending the message from the list of connections attached to the nanomsg socket.
4. Shared mutex is unlocked.
---- context switch ---
5. Connection is broken.
6. Connection mutex is locked.
7. Connection is deallocated.
8. Shared mutex is locked.
9. Connection is removed from the list of available connections.
10. Shared mutex is unlocked.
11. Connection mutex is unlocked.
12. Connection mutex is destroyed.
--- context switch ---
13. Tries to lock the mutex associated with the connection chosen for sending the message.
14. The lock is already destroyed.
15. FAILURE

How would you address that kind of the problem?

Martin



Other related posts: