djgroen/MPWide — pull request #14 by blootsvoets (2013-07-24 17:15:53+00:00)
Title: Added a test for MTO and the changes needed in MTO to support it

The direct storage of MPWPath and Socket in a vector caused some serious corruption problems when having concurrent modification. Moreover, some operations such as the thread_tmp *ta construction and auto-tuner were not done during CreatePathWithoutConnect, making them impossible to protect with mutexes outside the MPWide.

300 lines added are due to the test file, MPWTestConcurrent, which does:
- destroy any erroneous paths in new thread
- server accept in new thread
- connect and start sending and receiving in new thread
- get accepted path A from server in joined thread
- run server accept again in new thread
- send on path A in new thread
- recv on path A in new thread
- join all threads.

this is protected by mutexes:

use_rwmutex: write for destroy and createpath, read for connect, send and receive. This means that connect may not in any way modify global/static variables.

accept_destroy_mutex: makes destroy and accept mutually exclusive. This means accept must not rely on any variables modified by createpath. This is currently not true, the ports and cports variables are read by accept and modifiable by createpath (ports.push_back). In some cases, this will give problems.

destroy_mutex: for adding paths to be destroyed

log_mutex: makes log messages mutually exclusive. This prevents mishaps with cout (fairly common with verbose logging).