elle/discuss — pull request #1 by delitescere (2013-04-27 06:45:40+00:00)
Title: Thread safe sending, and small refactor

Noticed that the conditions to stop sending a message more than once aren't atomic, so this would fail to protect multiple sends if the message was held by multiple threads and they were attempting to send at the same time.

The new test emulates this situation using a single countdown latch in a test-modified deliver! method. When the send! method is protected by a mutex, though, this causes a deadlock situation which is broken by timeouts on the test's countdown latch. Nonetheless, the mutex in send! ensures that the deliver! method can only be called once. When the send! method is not protected by a mutex, the deadlock does not occur (as there is no outer mutex in send!) and the test fails, highlighting a lack of thread safety.

There was also a small refactoring to make the retrieval of valid users from ids more intentional and declarative (using a reject filter rather than an if statement).