Fix remaining problems that occur infrequently when running the eunit tests

Fix remaining problems that occur infrequently when running the eunit tests (problems due to race conditions).  The two remaining eunit test problems that remain are related to https://zeromq.jira.com/browse/LIBZMQ-496 (which causes "Device or resource busy (mutex.hpp:92)" for most of the remaining failures) and https://zeromq.jira.com/browse/LIBZMQ-478 (which causes "Assertion failed: ok (mailbox.cpp:79)").  The changes include proper error handling of a receive within the erlzmq2 thread, but they mainly focus on safe mutex usage for all operations.  The changes solve problems that previously occurred normally with socket destruction and context termination.  All the changes were verified by running the eunit tests continuously for more than 4 days under CentOS.