Menu

Tree [5c8a1d] master /
 History

HTTPS access


File Date Author Commit
 Downloads 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 build 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 docs 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 m4 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 man 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 .gitignore 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 Makefile.am 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 README 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 RELEASE_NOTES 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 acinclude.m4 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 aclocal.m4 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 config.h.in 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 configure 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 configure.ac 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 libtpool.h 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_debug.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_delta.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_init.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_shutdown.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_tasks.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge
 tpool_worker.c 2014-07-03 Bryan Costales Bryan Costales [5c8a1d] First official release to sourceforge

Read Me

libtpool.a	A general purpose thread poll library

To build, just run:
	
	tar xvf libtpool.tar
	make

Pthreads are mandatory and the build requires that pthread.h exist at
the system level.

To use:

	-------------------------------------------------------------------------
	Start up a thread pool:
	-------------------------------------------------------------------------

	#include "tpool.h"
	main()
	{
		TPOOL_CTX *     tpool_ctx       = NULL;
		char		buf[BUFSIZ];
		int		num_threads	= 100;

		tpool_ctx = tpool_init(num_threads, ebuf, sizeof ebuf);
		if (tpool_ctx == NULL)
			handle_error_here;


	-------------------------------------------------------------------------
	Shutdown the thread pool:
	-------------------------------------------------------------------------

		if (tpool_ctx != NULL)
			tpool_ctx = tpool_shutdown(tpool_ctx, ebuf, sizeof ebuf);


	-------------------------------------------------------------------------
	To use the threads, first create a function to be run by a thread:
	-------------------------------------------------------------------------

	void *
	function_to_run(void *arg, int *state)
	{
		// data passed in arg
		// if *state == TPOOL_WORKER_STATE_EXIT the thread pool is shutting down
	}
	
	-------------------------------------------------------------------------
	Optionally, either pass NULL or create a custom function to free your
	data when the thread finishes
	-------------------------------------------------------------------------

	void
	function_to_free(void *)
	{
	}

	-------------------------------------------------------------------------
	Launch a thread to run the function_to_run(). This call starts up an idle
	thread and runs the function using that thread. This function returns
	immediately while the thread runs asynchronously.
	-------------------------------------------------------------------------

	int  ret;
	char data[64]; // for example
	ret = bm_tpool_push_task(tpool_ctx, function_to_run, function_to_free, (void *)data, ebuf, sizeof ebuf);
	if (ret != 0)
		handle_error;


	-------------------------------------------------------------------------
	Debugging prints to standard out.
	Use 1 to turn on debugging, 0 to turn it off:
	-------------------------------------------------------------------------

	(void) tpool_debug_set(1); /* turn on  */
	(void) tpool_debug_set(0); /* turn off */

	-------------------------------------------------------------------------
	Find out how many worker threads are busy, or increase the pool size
	by a fixed amount. If delta is 0 just fetch the count. If delta is
	greater than 0, both increase the pool size and return the new count.
	-------------------------------------------------------------------------

	int count;
	int delta = 25;

	count = tpool_delta(tpool_ctx, delta);
	if (count == 0)
		handle_error_here;

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.