31 static size_t fibs(
size_t arg) {
32 if (arg < 2) {
return 1; }
33 return fibs(arg - 1) +
fibs(arg - 2);
37 printf(
"%s(at %d, dt %d, bl %zd)\n",
42 #define ATOMIC_BOOL_COMPARE_AND_SWAP(PTR, OLD, NEW) \
43 (__sync_bool_compare_and_swap(PTR, OLD, NEW))
55 arg = 30 + (random() % 10);
59 size_t res =
fibs(arg);
61 printf(
"%zd -- fibs(%zd) => %zd", tc, arg, res);
75 int main(
int argc,
char **argv) {
77 uint8_t max_threads = 8;
79 char *sz2_env = getenv(
"SZ2");
80 char *max_threads_env = getenv(
"MAX_THREADS");
81 if (sz2_env) { sz2 = atoi(sz2_env); }
82 if (max_threads_env) { max_threads = atoi(max_threads_env); }
97 for (
int i = 0; i < 4; i++) {
98 printf(
"scheduling...\n");
99 for (
int j = 0; j < 40; j++) {
101 size_t counterpressure = 0;
105 size_t msec = 10 * 1000 * counterpressure;
123 size_t counterpressure = 0;
131 printf(
"shutting down...\n");
134 for (
int i = 0; i <
limit; i++) {
136 (void)poll(NULL, 0, 10);
138 if (i == limit - 1) {
139 printf(
"cancelling thread in intentional infinite loop\n");
void Threadpool_Free(struct threadpool *t)
Free a threadpool.
threadpool_task_cb * task
Configuration for thread pool.
static void dump_stats(const char *prefix, struct threadpool_info *stats)
bool Threadpool_Shutdown(struct threadpool *t, bool kill_all)
Notify the threadpool's threads that the system is going to shut down soon.
Internal threadpool state.
static size_t fibs(size_t arg)
uint8_t task_ringbuf_size2
#define THREAD_SHUTDOWN_SECONDS
static void inf_loop_cb(void *env)
struct threadpool * Threadpool_Init(struct threadpool_config *cfg)
Initialize a threadpool, according to a config.
Statistics about the current state of the threadpool.
int main(int argc, char **argv)
static void task_cb(void *udata)
#define ATOMIC_BOOL_COMPARE_AND_SWAP(PTR, OLD, NEW)
void Threadpool_Stats(struct threadpool *t, struct threadpool_info *info)
If TI is non-NULL, fill out some statistics about the operating state of the thread pool...
bool Threadpool_Schedule(struct threadpool *t, struct threadpool_task *task, size_t *pushback)
Schedule a task in the threadpool.