Product SiteDocumentation Site


tc_run, tc_init, tc_worker_init, tc_worker_init, tc_set_diagnostic_fn, tc_set_stack_size — libtcr initialization


#include <tc/threaded_cr.h>

void tc_run(void (*func)(void *), void *data, char* name, int nr_of_workers);

void tc_init();

void tc_worker_init();

void tc_set_diagnostic_fn(diagnostic_fn f);

void tc_set_stack_size(int size);


The most convenient way of using the tc-library is to call tc_run(). Alternatively call tc_init() once, create you thread pool, call tc_worker_init() and tc_scheduler() in each thread of the pool.
tc_run() creates nr_of_workers threads using pthread_create(3) and calls tc_scheduler() in these threads. After that it calls the provided func. When func returns the thread pool of worker threads gets destroyed.
tc_set_diagnostic_fn() can be used to alter the target of the tc-library's emergency messages. By default they are written to stderr. This function is one of the few functions that might be called before tc_init() was called. In fact, it is recommended to call it before calling tc_init() because the tc-library might terminate the program if for example epoll_create(2) fails.
tc_set_stack_size() sets the stack size of tc_threads created later on with tc_thread_new(3) or tc_thread_pool_new(3) .


static void starter(void *unused)
	struct tc_thread *a, *b;

	a = tc_thread_new(func, "a", "func_a");
	b = tc_thread_new(func, "b", "func_b");


int main()
	tc_run(starter, NULL, "test", sysconf(_SC_NPROCESSORS_ONLN));
	return 0;


Philipp Reisner