merge from dev

This commit is contained in:
daanx 2024-03-03 17:43:52 -08:00
commit abb8eab9b2
4 changed files with 38 additions and 20 deletions

View file

@ -37,11 +37,12 @@ static int ITER = 50; // N full iterations destructing and re-creating a
// static int THREADS = 8; // more repeatable if THREADS <= #processors
// static int SCALE = 100; // scaling factor
#define STRESS // undefine for leak test
#define STRESS // undefine for leak test
static bool allow_large_objects = true; // allow very large objects? (set to `true` if SCALE>100)
static size_t use_one_size = 0; // use single object size of `N * sizeof(uintptr_t)`?
static bool main_participates = false; // main thread participates as a worker too
// #define USE_STD_MALLOC
#ifdef USE_STD_MALLOC
@ -301,14 +302,15 @@ static void run_os_threads(size_t nthreads, void (*fun)(intptr_t)) {
thread_entry_fun = fun;
DWORD* tids = (DWORD*)custom_calloc(nthreads,sizeof(DWORD));
HANDLE* thandles = (HANDLE*)custom_calloc(nthreads,sizeof(HANDLE));
for (uintptr_t i = 1; i < nthreads; i++) {
const size_t start = (main_participates ? 1 : 0);
for (size_t i = start; i < nthreads; i++) {
thandles[i] = CreateThread(0, 8*1024, &thread_entry, (void*)(i), 0, &tids[i]);
}
fun(0); // run the main thread as well
for (size_t i = 1; i < nthreads; i++) {
if (main_participates) fun(0); // run the main thread as well
for (size_t i = start; i < nthreads; i++) {
WaitForSingleObject(thandles[i], INFINITE);
}
for (size_t i = 1; i < nthreads; i++) {
for (size_t i = start; i < nthreads; i++) {
CloseHandle(thandles[i]);
}
custom_free(tids);
@ -335,12 +337,13 @@ static void run_os_threads(size_t nthreads, void (*fun)(intptr_t)) {
thread_entry_fun = fun;
pthread_t* threads = (pthread_t*)custom_calloc(nthreads,sizeof(pthread_t));
memset(threads, 0, sizeof(pthread_t) * nthreads);
const size_t start = (main_participates ? 1 : 0);
//pthread_setconcurrency(nthreads);
for (size_t i = 1; i < nthreads; i++) {
for (size_t i = start; i < nthreads; i++) {
pthread_create(&threads[i], NULL, &thread_entry, (void*)i);
}
fun(0); // run the main thread as well
for (size_t i = 1; i < nthreads; i++) {
if (main_participates) fun(0); // run the main thread as well
for (size_t i = start; i < nthreads; i++) {
pthread_join(threads[i], NULL);
}
custom_free(threads);