未验证 提交 802ba5c6 编写于 作者: I Ian Craggs 提交者: GitHub

Merge pull request #1046 from Foxhound31/fix_close_thread_handle

Fix issue with thread handles on Windows platform (close them after thread creation)
......@@ -55,9 +55,8 @@
* Start a new thread
* @param fn the function to run, must be of the correct signature
* @param parameter pointer to the function parameter, can be NULL
* @return the new thread
*/
thread_type Thread_start(thread_fn fn, void* parameter)
void Thread_start(thread_fn fn, void* parameter)
{
#if defined(_WIN32) || defined(_WIN64)
thread_type thread = NULL;
......@@ -69,6 +68,7 @@ thread_type Thread_start(thread_fn fn, void* parameter)
FUNC_ENTRY;
#if defined(_WIN32) || defined(_WIN64)
thread = CreateThread(NULL, 0, fn, parameter, 0, NULL);
CloseHandle(thread);
#else
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
......@@ -77,7 +77,6 @@ thread_type Thread_start(thread_fn fn, void* parameter)
pthread_attr_destroy(&attr);
#endif
FUNC_EXIT;
return thread;
}
......@@ -563,14 +562,13 @@ int cond_test()
{
int rc = 0;
cond_type cond = Thread_create_cond();
thread_type thread;
printf("Post secondary so it should return immediately\n");
rc = Thread_signal_cond(cond);
assert("rc 0 from signal cond", rc == 0, "rc was %d", rc);
printf("Starting secondary thread\n");
thread = Thread_start(cond_secondary, (void*)cond);
Thread_start(cond_secondary, (void*)cond);
sleep(3);
......@@ -614,7 +612,6 @@ int sem_test()
{
int rc = 0;
sem_type sem = Thread_create_sem();
thread_type thread;
printf("Primary semaphore pointer %p\n", sem);
......@@ -629,7 +626,7 @@ int sem_test()
assert("rc 1 from check_sem", rc == 1, "rc was %d", rc);
printf("Starting secondary thread\n");
thread = Thread_start(sem_secondary, (void*)sem);
Thread_start(sem_secondary, (void*)sem);
sleep(3);
rc = Thread_check_sem(sem);
......
......@@ -59,7 +59,7 @@
int Thread_destroy_cond(cond_type);
#endif
LIBMQTT_API thread_type Thread_start(thread_fn, void*);
LIBMQTT_API void Thread_start(thread_fn, void*);
LIBMQTT_API mutex_type Thread_create_mutex(int*);
LIBMQTT_API int Thread_lock_mutex(mutex_type);
......
......@@ -258,7 +258,6 @@ int test_sem(struct Options options)
START_TIME_TYPE start;
long duration;
sem_type sem = Thread_create_sem(&rc);
thread_type thread;
MyLog(LOGA_INFO, "Starting semaphore test");
fprintf(xml, "<testcase classname=\"test\" name=\"%s\"", testname);
......@@ -306,7 +305,7 @@ int test_sem(struct Options options)
assert("duration is 2s", duration >= 1500L, "duration was %ld", duration);
MyLog(LOGA_DEBUG, "Starting secondary thread");
thread = Thread_start(sem_secondary, (void*)sem);
Thread_start(sem_secondary, (void*)sem);
mysleep(2);
MyLog(LOGA_DEBUG, "post secondary");
......@@ -360,7 +359,6 @@ int test_cond(struct Options options)
START_TIME_TYPE start;
long duration;
cond_type cond = Thread_create_cond(&rc);
thread_type thread;
MyLog(LOGA_INFO, "Starting condition variable test");
fprintf(xml, "<testcase classname=\"cond\" name=\"%s\"", testname);
......@@ -399,7 +397,7 @@ int test_cond(struct Options options)
assert("rc 0 from signal cond", rc == 0, "rc was %d", rc);
MyLog(LOGA_DEBUG, "Starting secondary thread");
thread = Thread_start(cond_secondary, (void*)cond);
Thread_start(cond_secondary, (void*)cond);
MyLog(LOGA_DEBUG, "wait for secondary thread to enter second wait");
mysleep(2);
......@@ -448,7 +446,6 @@ int test_mutex(struct Options options)
char* testname = "test_mutex";
int rc = 0;
mutex_type mutex = Thread_create_mutex(&rc);
thread_type thread;
START_TIME_TYPE start;
long duration;
......@@ -465,7 +462,7 @@ int test_mutex(struct Options options)
assert("duration is very low", duration < 5L, "duration was %ld", duration);
MyLog(LOGA_DEBUG, "Starting secondary thread");
thread = Thread_start(mutex_secondary, (void*)mutex);
Thread_start(mutex_secondary, (void*)mutex);
mysleep(2);
rc = Thread_unlock_mutex(mutex); /* let background thread have it */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册