4 #include "uthreadpool.h"
7 u_thread_pool_t gThreadPoolHandle = NULL;
14 printf("[TASK] Task is executing: data: %s\n", (char *) data);
16 //Signal the condition that task has been completed
17 printf("[TASK] Signaling the condition\n");
21 void testThreadPool(void)
23 char *string = "Test glib thread pool";
25 //Initialize the mutex
26 printf("[testThreadPool] Initializing mutex\n");
29 //Initialize the thread pool
30 printf("[testThreadPool] Initializing thread pool\n");
31 if (CA_STATUS_OK != u_thread_pool_init(2, &gThreadPoolHandle))
33 printf("thread_pool_init failed!\n");
38 printf("[testThreadPool] Creating mutex\n");
39 gMutex = u_mutex_new();
42 printf("[testThreadPool] Failed to create mutex!\n");
46 //Create the condition
47 printf("[testThreadPool] Creating Condition\n");
51 printf("[testThreadPool] Failed to create condition!\n");
58 printf("[testThreadPool] Locking the mutex\n");
61 //Add task to thread pool
62 printf("[testThreadPool] Adding the task to thread pool\n");
63 if (CA_STATUS_OK != u_thread_pool_add_task(gThreadPoolHandle, task, (void *) string))
65 printf("[testThreadPool] thread_pool_add_task failed!\n");
67 u_mutex_unlock(gMutex);
73 //Wait for the task to be executed
74 printf("[testThreadPool] Waiting for the task to be completed\n");
75 u_cond_wait(gCond, gMutex);
78 printf("[testThreadPool] Got the signal and unlock the mutex\n");
79 u_mutex_unlock(gMutex);
81 printf("[testThreadPool] Task is completed and terminating threadpool\n");
84 u_thread_pool_free(gThreadPoolHandle);
86 printf("Exiting from testThreadPool\n");
91 printf(" =====================================================================\n");
92 printf("| Welcome to Theadpool testing |\n");
93 printf("|---------------------------------------------------------------------|\n");
94 printf("| ** Options ** |\n");
95 printf("| 1 - Test Threadpool functionality |\n");
96 printf("| 0 - Terminate test |\n");
99 static void startTesting(void)
104 scanf("%d", &choice);
109 printf("Terminating test.....\n");
115 printf("Invalid input...\n");