This commit is contained in:
2026-08-30 01:48:03 +08:00
parent 84ebd52c24
commit 7940b67827
170 changed files with 2704 additions and 21276 deletions
-39
View File
@@ -1,39 +0,0 @@
#include "c_ThreadPool.h"
#include <stdlib.h>
#include <stdio.h>
// Sample payload mimicking work
void compute_square(void* arg) {
int val = *(int*)arg;
printf("[Thread Pool Task] Processing square of %d = %d\n", val, val * val);
free(arg); // Free parameter memory passed during submission
}
int main(int argc, char** argv){
// Create a pool with 4 worker threads and a max capacity of 20 pending tasks
c_ThreadPool_t pool = {0};
c_ThreadPool_Init(&pool, 4, 20, 10, 500);
printf("--- Thread Pool Initialized with 4 Workers ---\n");
// Queue 10 dynamic processing computations
for (int i = 1; i <= 10; i++) {
int* num = (int*)malloc(sizeof(int));
*num = i;
if (!c_ThreadPool_Submit(&pool, compute_square, num)) {
fprintf(stderr, "[Thread Pool Task] Submit %d failed\n", i);
}
}
// Force main to simulate work before cleaning up
printf("All tasks submitted. Waiting for processing to settle...\n");
c_Thread_Sleep(2000);
printf("--- Destroying Thread Pool ---\n");
c_ThreadPool_Destroy(&pool);
printf("Thread pool destroyed cleanly.\n");
return 0;
}