Revision: 55111
http://brlcad.svn.sourceforge.net/brlcad/?rev=55111&view=rev
Author: brlcad
Date: 2013-04-10 17:28:27 +0000 (Wed, 10 Apr 2013)
Log Message:
-----------
fix a race condition adding new values to the cleanup list. need to
semaphore-protect the additions. the destructor should be save, but protect
there as well for consistency.
Modified Paths:
--------------
brlcad/trunk/src/libbu/thread.cpp
Modified: brlcad/trunk/src/libbu/thread.cpp
===================================================================
--- brlcad/trunk/src/libbu/thread.cpp 2013-04-10 17:26:05 UTC (rev 55110)
+++ brlcad/trunk/src/libbu/thread.cpp 2013-04-10 17:28:27 UTC (rev 55111)
@@ -26,7 +26,9 @@
# include <pthread.h>
#endif
+#include "bu.h"
+
#if defined(HAVE_THREAD_LOCAL)
static thread_local int thread_cpu = 0;
@@ -50,7 +52,11 @@
protected:
void set(T& val) {
T* value = new T(val);
+
+ bu_semaphore_acquire(BU_SEM_THREAD);
vals.push_back(value);
+ bu_semaphore_release(BU_SEM_THREAD);
+
pthread_setspecific(key, value);
}
T* get() {
@@ -59,17 +65,20 @@
}
public:
ThreadLocal() {
- int cpu0 = 0;
+ T init = 0;
pthread_key_create(&key, NULL);
- set(cpu0);
+ set(init);
}
~ThreadLocal() {
pthread_key_delete(key);
+
+ bu_semaphore_acquire(BU_SEM_THREAD);
while (!vals.empty()) {
delete vals.back();
vals.pop_back();
}
vals.clear();
+ bu_semaphore_release(BU_SEM_THREAD);
}
ThreadLocal& operator=(T& val) {
set(val);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits