Commit 3f45551c authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

merge changeset 11870 from the 2.0.0 branch to main. addresses #1750

git-svn-id: file:///svn/toku/tokudb@11878 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9025edfe
// test for a pthread handle leak
#include "toku_portability.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <unistd.h>
#include <toku_pthread.h>
static void *mythreadfunc(void *arg) {
return arg;
}
int main(void) {
#define N 1000000
int i;
for (i=0; i<N; i++) {
int r;
toku_pthread_t tid;
r = toku_pthread_create(&tid, NULL, mythreadfunc, (void *)i);
assert(r == 0);
void *ret;
r = toku_pthread_join(tid, &ret);
assert(r == 0 && ret == (void*)i);
}
printf("ok\n"); fflush(stdout);
return 0;
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <toku_pthread.h> #include <toku_pthread.h>
#include "memory.h"
int int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *restrict rwlock, const toku_pthread_rwlockattr_t *restrict attr) { toku_pthread_rwlock_init(toku_pthread_rwlock_t *restrict rwlock, const toku_pthread_rwlockattr_t *restrict attr) {
...@@ -152,7 +153,7 @@ toku_pthread_start(LPVOID a) { ...@@ -152,7 +153,7 @@ toku_pthread_start(LPVOID a) {
int int
toku_pthread_create(toku_pthread_t *threadptr, const toku_pthread_attr_t *attr, void *(*f)(void *), void *arg) { toku_pthread_create(toku_pthread_t *threadptr, const toku_pthread_attr_t *attr, void *(*f)(void *), void *arg) {
size_t stacksize = 0; size_t stacksize = 0;
toku_pthread_t thread = malloc(sizeof (struct toku_pthread)); toku_pthread_t thread = toku_malloc(sizeof (struct toku_pthread));
if (thread == 0) if (thread == 0)
return ENOMEM; return ENOMEM;
if (attr) if (attr)
...@@ -161,16 +162,24 @@ toku_pthread_create(toku_pthread_t *threadptr, const toku_pthread_attr_t *attr, ...@@ -161,16 +162,24 @@ toku_pthread_create(toku_pthread_t *threadptr, const toku_pthread_attr_t *attr,
thread->arg = arg; thread->arg = arg;
// _beginthread or CreateThread // _beginthread or CreateThread
thread->handle = CreateThread(NULL, stacksize, toku_pthread_start, thread, 0, &thread->id); thread->handle = CreateThread(NULL, stacksize, toku_pthread_start, thread, 0, &thread->id);
if (thread->handle == NULL) {
toku_free(thread);
return ENOMEM;
}
*threadptr = thread; *threadptr = thread;
return 0; return 0;
} }
int int
toku_pthread_join(toku_pthread_t thread, void **ret) { toku_pthread_join(toku_pthread_t thread, void **ret) {
WaitForSingleObject(thread->handle, INFINITE); DWORD r;
r = WaitForSingleObject(thread->handle, INFINITE);
assert(r != WAIT_FAILED);
if (ret) if (ret)
*ret = thread->ret; *ret = thread->ret;
free(thread); BOOL b;
b = CloseHandle(thread->handle); assert(b != 0);
toku_free(thread);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment