diff --git a/lib/grading/test_threads.c b/lib/grading/test_threads.c index 1f1c4f5..3188b2c 100644 --- a/lib/grading/test_threads.c +++ b/lib/grading/test_threads.c @@ -1,8 +1,10 @@ +#include #include #include #include +#include -#define PROCESS_COUNT 100 +#define PROCESS_COUNT 1 void do_test_threads(void) { debug_printf("[do_test_threads]\n"); @@ -14,4 +16,19 @@ void do_test_threads(void) { debug_printf("TEST_THREADS: spawn %u\n", i); CHECK_ERR(spawn_load_by_name("mallocator", &(si[i]), &(pid[i]))); } + + // while (true) { + // debug_printf("[do_test_threads]: processes alive: "); + + // struct spawninfo* process = spawn_get_process_list(); + // while (process != NULL) { + // printf("%d, ", process->pid); + // process = process->next; + // } + + // printf("\n"); + + // //wait for 1 second but handle events in the mean time + // barrelfish_usleep(1000000); + // } } diff --git a/usr/mallocator/main.c b/usr/mallocator/main.c index bc03868..3ae49f1 100644 --- a/usr/mallocator/main.c +++ b/usr/mallocator/main.c @@ -19,8 +19,12 @@ #include #define NUM_SMALL_BUFFERS 128 +#define NUM_THREADS 16 -static void test_large_buffer(void) { +static struct thread* threads[NUM_THREADS]; + +__attribute__((__used__)) +static int test_large_buffer(void * __args) { //allocate a 256 MiB buffer debug_printf("allocating 256MiB buffer\n"); char * big_buf = malloc(1<<28); @@ -33,8 +37,12 @@ static void test_large_buffer(void) { debug_printf("freeing 256MiB buffer\n"); free(big_buf); + debug_printf("thread done!\n"); + + return 0; } +__attribute__((__used__)) static void test_many_buffers(void) { char* buffers[NUM_SMALL_BUFFERS]; @@ -52,10 +60,23 @@ static void test_many_buffers(void) { } } + +static void test_multi_thread(void) { + for (int i = 0; i < NUM_THREADS; ++i) { + threads[i] = thread_create(test_large_buffer, NULL); + } + + //wait for the threads + for (int i = 0; i < NUM_THREADS; ++i) { + thread_join(threads[i], NULL); + } +} + int main(int argc, char *argv[]) { - test_large_buffer(); - test_many_buffers(); + // test_large_buffer(); + // test_many_buffers(); + test_multi_thread(); debug_printf("i am done!\n"); } \ No newline at end of file