summaryrefslogtreecommitdiff
path: root/src/os_win/os_thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_win/os_thread.c')
-rw-r--r--src/os_win/os_thread.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/os_win/os_thread.c b/src/os_win/os_thread.c
index 4c8f212bb4f..1ecf53e382e 100644
--- a/src/os_win/os_thread.c
+++ b/src/os_win/os_thread.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2014-2016 MongoDB, Inc.
+ * Copyright (c) 2014-2017 MongoDB, Inc.
* Copyright (c) 2008-2014 WiredTiger, Inc.
* All rights reserved.
*
@@ -24,9 +24,11 @@ __wt_thread_create(WT_SESSION_IMPL *session,
WT_FULL_BARRIER();
/* Spawn a new thread of control. */
- *tidret = (HANDLE)_beginthreadex(NULL, 0, func, arg, 0, NULL);
- if (*tidret != 0)
+ tidret->id = (HANDLE)_beginthreadex(NULL, 0, func, arg, 0, NULL);
+ if (tidret->id != 0) {
+ tidret->created = true;
return (0);
+ }
WT_RET_MSG(session, __wt_errno(), "thread create: _beginthreadex");
}
@@ -40,6 +42,10 @@ __wt_thread_join(WT_SESSION_IMPL *session, wt_thread_t tid)
{
DWORD windows_error;
+ /* Only attempt to join if thread was created successfully */
+ if (!tid.created)
+ return (0);
+
/*
* Joining a thread isn't a memory barrier, but WiredTiger commonly
* sets flags and or state and then expects worker threads to halt.
@@ -48,7 +54,7 @@ __wt_thread_join(WT_SESSION_IMPL *session, wt_thread_t tid)
WT_FULL_BARRIER();
if ((windows_error =
- WaitForSingleObject(tid, INFINITE)) != WAIT_OBJECT_0) {
+ WaitForSingleObject(tid.id, INFINITE)) != WAIT_OBJECT_0) {
if (windows_error == WAIT_FAILED)
windows_error = __wt_getlasterror();
__wt_errx(session, "thread join: WaitForSingleObject: %s",
@@ -58,13 +64,14 @@ __wt_thread_join(WT_SESSION_IMPL *session, wt_thread_t tid)
return (WT_PANIC);
}
- if (CloseHandle(tid) == 0) {
+ if (CloseHandle(tid.id) == 0) {
windows_error = __wt_getlasterror();
__wt_errx(session, "thread join: CloseHandle: %s",
__wt_formatmessage(session, windows_error));
return (__wt_map_windows_error(windows_error));
}
+ tid.created = false;
return (0);
}