Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_thread_pool_wait.c
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
29#include "nilorea/n_common.h"
30#include "nilorea/n_log.h"
32
33#include <stdio.h>
34#include <unistd.h>
35
36static void* slow_proc(void* p) {
37 (void)p;
38 usleep(1500000); /* 1.5 s, as a real audit request against a remote host */
39 return NULL;
40}
41
42int main(void) {
44 /* one active thread, no waiting slots: exactly what the scanner builds for a
45 single-endpoint audit (new_thread_pool(nthr, 0) with nthr == 1) */
47 if (!pool) {
48 printf("FAIL: no pool\n");
49 return 1;
50 }
51 if (add_threaded_process(pool, &slow_proc, NULL, NORMAL_PROC) == FALSE) {
52 printf("FAIL: could not add proc\n");
53 return 1;
54 }
55 wait_for_threaded_pool(pool); /* hung here before the fix */
57 printf("ex_thread_pool_wait: all checks passed\n");
58 return 0;
59}
static NETWORK_POOL * pool
int main(void)
static void * slow_proc(void *p)
#define LOG_ERR
error conditions
Definition n_log.h:100
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
Definition n_log.c:123
#define NORMAL_PROC
processing mode for added func, synced start, can be queued
THREAD_POOL * new_thread_pool(size_t nbmaxthr, size_t nb_max_waiting)
Create a new pool of nbmaxthr threads.
int add_threaded_process(THREAD_POOL *thread_pool, void *(*func_ptr)(void *param), void *param, int mode)
add a function and params to a thread pool
int wait_for_threaded_pool(THREAD_POOL *thread_pool)
Wait for the thread pool to become idle (no active threads, empty waiting list), blocking without pol...
int destroy_threaded_pool(THREAD_POOL **pool, unsigned int delay)
Stop every thread of a pool and free it.
Structure of a thread pool.
Common headers and low-level functions & define.
Generic log system.
Thread pool declaration.