Implement WinNT condition variables, add semaphors
This commit is contained in:
50
main.c
50
main.c
@@ -45,34 +45,57 @@ int factor(int x)
|
||||
|
||||
void factor_task(void *arg)
|
||||
{
|
||||
printf("Task start\n");
|
||||
fflush(stdout);
|
||||
printf("Factor: %d\n", factor(42));
|
||||
fflush(stdout);
|
||||
//printf("Task start\n");
|
||||
//fflush(stdout);
|
||||
//printf("Factor: %d\n", factor(42));
|
||||
//fflush(stdout);
|
||||
volatile int i = factor(16);
|
||||
|
||||
//printf("Factor: %d\n", factor(15));
|
||||
}
|
||||
|
||||
#include <x86intrin.h>
|
||||
|
||||
void bar()
|
||||
{
|
||||
bh_thread_pool_t *pool;
|
||||
bh_task_t *task;
|
||||
size_t i;
|
||||
|
||||
bh_uint64_t start, end;
|
||||
|
||||
printf("Pool create\n");
|
||||
fflush(stdout);
|
||||
//printf("Pool create\n");
|
||||
//fflush(stdout);
|
||||
pool = bh_thread_pool_new(16);
|
||||
|
||||
printf("Prepare\n");
|
||||
fflush(stdout);
|
||||
for (i = 0; i < 32; i++)
|
||||
if (!pool)
|
||||
{
|
||||
printf("Task create\n");
|
||||
fflush(stdout);
|
||||
//printf("Pool creation error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
//printf("Prepare\n");
|
||||
//fflush(stdout);
|
||||
|
||||
start = __rdtsc();
|
||||
|
||||
for (i = 0; i < 128 * 1024; i++)
|
||||
{
|
||||
//printf("Task create\n");
|
||||
//fflush(stdout);
|
||||
task = bh_task_new(factor_task, NULL, BH_THREAD_CLEANUP);
|
||||
bh_thread_pool_add(pool, task);
|
||||
}
|
||||
|
||||
//system("pause");
|
||||
|
||||
bh_thread_pool_wait(pool);
|
||||
end = __rdtsc();
|
||||
bh_thread_pool_free(pool);
|
||||
|
||||
|
||||
|
||||
printf("Elapsed: %llu\n", end - start);
|
||||
//system("pause");
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -81,11 +104,12 @@ int main()
|
||||
void *iter;
|
||||
size_t i, j;
|
||||
|
||||
foo();
|
||||
//foo();
|
||||
|
||||
printf("Thread?\n");
|
||||
fflush(stdout);
|
||||
bar();
|
||||
return 0;
|
||||
|
||||
queue = bh_queue_new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user