37 printf(
"%s -- %8ld thread tasks / sec -- (at %d, dt %d, bl %zd) -- delta %zd\n",
44 #define ATOMIC_BOOL_COMPARE_AND_SWAP(PTR, OLD, NEW) \
45 (__sync_bool_compare_and_swap(PTR, OLD, NEW))
48 #define SPIN_ADJ(F, ADJ) \
52 if (ATOMIC_BOOL_COMPARE_AND_SWAP(&F, v, v + ADJ)) { \
58 static size_t fibs(
size_t arg) {
59 if (arg < 2) {
return 1; }
60 return fibs(arg - 1) +
fibs(arg - 2);
70 int main(
int argc,
char **argv) {
72 uint8_t max_threads = 8;
74 char *sz2_env = getenv(
"SZ2");
75 char *max_threads_env = getenv(
"MAX_THREADS");
76 if (sz2_env) { sz2 = atoi(sz2_env); }
77 if (max_threads_env) { max_threads = atoi(max_threads_env); }
93 gettimeofday(&tv, NULL);
94 time_t last_sec = tv.tv_sec;
95 size_t counterpressure = 0;
99 gettimeofday(&tv, NULL);
100 if (tv.tv_sec > last_sec) {
101 last_sec = tv.tv_sec;
109 if ((ticks & 15) == 0) {
113 for (
size_t i = 0; i < 1000; i++) {
115 size_t msec = i * 1000 * counterpressure;
int main(int argc, char **argv)
threadpool_task_cb * task
Configuration for thread pool.
static size_t fibs(size_t arg)
Internal threadpool state.
uint8_t task_ringbuf_size2
struct threadpool * Threadpool_Init(struct threadpool_config *cfg)
Initialize a threadpool, according to a config.
Statistics about the current state of the threadpool.
static void task_cb(void *udata)
static void dump_stats(const char *prefix, struct threadpool_info *stats, size_t ticks)
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.