You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 07:25:00 UTC
svn commit: r1131747 - /incubator/mesos/trunk/src/zookeeper.cpp
Author: benh
Date: Sun Jun 5 05:25:00 2011
New Revision: 1131747
URL: http://svn.apache.org/viewvc?rev=1131747&view=rev
Log:
Cool bug: apparently on Mac OS X there are issues doing a __attribute((constructor)) in one thread that uses a static library that might not have been initialized yet. This commit does a work around that doesn't use the __attribute__((constructor)).
Modified:
incubator/mesos/trunk/src/zookeeper.cpp
Modified: incubator/mesos/trunk/src/zookeeper.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/zookeeper.cpp?rev=1131747&r1=1131746&r2=1131747&view=diff
==============================================================================
--- incubator/mesos/trunk/src/zookeeper.cpp (original)
+++ incubator/mesos/trunk/src/zookeeper.cpp Sun Jun 5 05:25:00 2011
@@ -247,14 +247,22 @@ protected:
};
-static void __attribute__((constructor)) init()
+Watcher::Watcher()
{
- manager = Process::spawn(new WatcherProcessManager());
-}
+ // Confirm we have allocated the WatcherProcessManager.
+ static volatile bool initialized = false;
+ static volatile bool initializing = true;
+
+ // Confirm everything is initialized.
+ if (!initialized) {
+ if (__sync_bool_compare_and_swap(&initialized, false, true)) {
+ manager = Process::spawn(new WatcherProcessManager());
+ initializing = false;
+ }
+ }
+ while (initializing);
-Watcher::Watcher()
-{
Process::spawn(new WatcherProcess(this));
}