diff --git a/bin/example b/bin/example index 0d419c7..43cac62 100755 Binary files a/bin/example and b/bin/example differ diff --git a/build.sh b/build.sh index af47bf7..1a1708c 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ # This script builds the project mkdir -p build +mkdir -p bin cd ./build cmake .. make diff --git a/example b/example index e227675..43cac62 100755 Binary files a/example and b/example differ diff --git a/include/threadlib/threadlib.c b/include/threadlib/threadlib.c index 4807015..87fe2d1 100644 --- a/include/threadlib/threadlib.c +++ b/include/threadlib/threadlib.c @@ -61,7 +61,15 @@ void *__thread_master_init__(void *params) printf("Thread Master - Success: Ready.\n"); - thread_master_assign_new_job(param->__thread_worker__, param->custom_params); + if (param->__thread_worker__ == NULL) + { + fprintf(stderr, "Thread Master - Info: No task given, use \"thread_master_assign_new_job\" to run a task\n"); + } + else + { + thread_master_assign_new_job(param->__thread_worker__, param->custom_params); + } + return NULL; } @@ -84,6 +92,7 @@ void thread_master_init(int max_threads, void *(*__thread_worker__)(void *), voi fprintf(stderr, "Thread Master - Error: Failed to create thread master.\n"); exit(EXIT_FAILURE); } + isThreadMasterRunning = 1; pthread_detach(thread_master); diff --git a/src/main.c b/src/main.c index 5b8ed9b..3b88ee5 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,8 @@ void *thread_worker(void *params) return NULL; } + sleep_ms(100); + custom->a += 10; printf("Thread %d - WE ARE RUNNING THIS TASK\n", param->thread_id); @@ -33,9 +35,17 @@ int main(void) { custom_params_t *custom_params = (custom_params_t *)malloc(sizeof(custom_params_t)); custom_params->a = 0; - thread_master_init(MAX_THREAD, thread_worker, NULL); + thread_master_init(MAX_THREAD, NULL, custom_params); + + sleep_ms(1000); + + thread_master_assign_new_job(thread_worker, custom_params); + thread_master_assign_new_job(thread_worker, custom_params); + thread_master_assign_new_job(thread_worker, custom_params); thread_master_free(); printf("Custom Params: %d\n", custom_params->a); + + free(custom_params); return 0; } \ No newline at end of file