![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
destroy_threaded_pool() does not drop queued jobs silently. More...
#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_thread_pool.h"#include <stdio.h>#include <stdlib.h>#include <unistd.h>Go to the source code of this file.
Functions | |
| static void | discard_job (void *p) |
| Discard function: releases a param that will never be run. | |
| int | main (void) |
| static int | run (unsigned int delay) |
| Queue four slow jobs on a one thread pool and destroy it. | |
| static void * | slow_job (void *p) |
| A job that takes 300 ms and releases its own param. | |
Variables | |
| static pthread_mutex_t | count_lock = PTHREAD_MUTEX_INITIALIZER |
| Guards the two counters. | |
| static int | discarded = 0 |
| static int | ran = 0 |
| Jobs that ran, and params the discard function released. | |
destroy_threaded_pool() does not drop queued jobs silently.
One thread, one slow job running and three queued behind it. With a retry budget shorter than the running job, destroy gives up waiting, joins the thread - which still waits for the running job - and discards the three queued ones without running them. Their params used to go with them, unreleased and unmentioned; under a leak checker that was three leaks and nowhere else was it visible.
Now each discarded param is handed to the pool's discard function. This checks that exactly the three queued jobs are discarded, that the running one completes, and that a budget long enough to drain the queue runs all four and discards none. Run under ASan, a param that nobody releases fails the run.
Definition in file ex_thread_pool_discard.c.
|
static |
Discard function: releases a param that will never be run.
| p | A malloc'd int. |
Definition at line 65 of file ex_thread_pool_discard.c.
References count_lock, and discarded.
Referenced by run().
| int main | ( | void | ) |
Definition at line 98 of file ex_thread_pool_discard.c.
References discarded, failures, LOG_NULL, ran, run, and set_log_level().
|
static |
Queue four slow jobs on a one thread pool and destroy it.
| delay | destroy_threaded_pool()'s retry delay, in microseconds. |
Definition at line 77 of file ex_thread_pool_discard.c.
References add_threaded_process(), destroy_threaded_pool(), discard_job(), discarded, new_thread_pool(), NORMAL_PROC, pool, ran, set_thread_pool_discard(), and slow_job().
|
static |
A job that takes 300 ms and releases its own param.
| p | A malloc'd int. |
Definition at line 52 of file ex_thread_pool_discard.c.
References count_lock, and ran.
Referenced by run().
|
static |
Guards the two counters.
Definition at line 45 of file ex_thread_pool_discard.c.
Referenced by discard_job(), and slow_job().
|
static |
Definition at line 43 of file ex_thread_pool_discard.c.
Referenced by discard_job(), main(), and run().
|
static |
Jobs that ran, and params the discard function released.
Definition at line 43 of file ex_thread_pool_discard.c.
Referenced by main(), run(), and slow_job().