Author: oracle
Date: Mon Jun 30 21:21:40 2008
New Revision: 27624
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27624&view=rev
Log:
Fixed a thread pool segfault. Condition variables must be deleted
and only then the mutexes which the condition variables use. The
segfault was caused by the deletion of mutexes which still active
condition variables referenced. Reversing the cleanup order made
things segfault free.
Modified:
trunk/src/network_worker.cpp
Modified: trunk/src/network_worker.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.cpp?rev=27624&r1=27623&r2=27624&view=diff
==============================================================================
--- trunk/src/network_worker.cpp (original)
+++ trunk/src/network_worker.cpp Mon Jun 30 21:21:40 2008
@@ -766,7 +766,6 @@
manager::~manager()
{
if(active_) {
-
managed = false;
for(size_t shard = 0; shard != NUM_SHARDS; ++shard) {
@@ -775,22 +774,28 @@
socket_errors[shard] = 0;
}
- cond[shard]->notify_all();
+ cond[shard]->notify_all();
for(std::map<Uint32,threading::thread*>::const_iterator
i = threads[shard].begin(); i != threads[shard].end(); ++i) {
DBG_NW << "waiting for thread " << i->first <<
" to exit...\n";
+ (*i->second).join() ;
delete i->second;
DBG_NW << "thread exited...\n";
}
- threads[shard].clear();
+ // Condition variables must be deleted first as
+ // they make reference to mutexs. If the mutexs
+ // are destroyed first, the condition variables
+ // will access memory already freed by way of
+ // stale mutex. Bad things will follow. ;)
+ threads[shard].clear();
+ delete cond[shard];
+ cond[shard] = NULL;
delete shard_mutexes[shard];
- shard_mutexes[shard] = NULL;
- delete cond[shard];
- cond[shard] = NULL;
- }
-
- delete stats_mutex;
+ shard_mutexes[shard] = NULL;
+ }
+
+ delete stats_mutex;
delete schemas_mutex;
delete received_mutex;
stats_mutex = 0;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits