summaryrefslogtreecommitdiff
path: root/node/Thread.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2014-08-21 17:49:05 -0700
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2014-08-21 17:49:05 -0700
commitde4e29288d30183ca78a5e0878431ed47fa58b8f (patch)
tree5b944e4176ead99473b2457386de315aa87aa405 /node/Thread.hpp
parent44d58ee871c498646213c01d1cd0417c2d537056 (diff)
downloadinfinitytier-de4e29288d30183ca78a5e0878431ed47fa58b8f.tar.gz
infinitytier-de4e29288d30183ca78a5e0878431ed47fa58b8f.zip
Fix for crazy Windows threading bug... repeatedly adding and removing a network now doesn't leave networks in limbo.
Diffstat (limited to 'node/Thread.hpp')
-rw-r--r--node/Thread.hpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/node/Thread.hpp b/node/Thread.hpp
index a796af33..e02cdde6 100644
--- a/node/Thread.hpp
+++ b/node/Thread.hpp
@@ -31,12 +31,13 @@
#include <stdexcept>
#include "Constants.hpp"
-#include "AtomicCounter.hpp"
#ifdef __WINDOWS__
+#include <WinSock2.h>
#include <Windows.h>
#include <string.h>
+#include "Mutex.hpp"
namespace ZeroTier {
@@ -56,6 +57,7 @@ public:
throw()
{
_th = NULL;
+ _tid = 0;
}
template<typename C>
@@ -71,8 +73,15 @@ public:
static inline void join(const Thread &t)
{
- if (t._th != NULL)
- WaitForSingleObject(t._th,INFINITE);
+ if (t._th != NULL) {
+ for(;;) {
+ DWORD ec = STILL_ACTIVE;
+ GetExitCodeThread(t._th,&ec);
+ if (ec == STILL_ACTIVE)
+ WaitForSingleObject(t._th,1000);
+ else break;
+ }
+ }
}
static inline void sleep(unsigned long ms)