Menu

Tree [r6] /
 History

HTTPS access


File Date Author Commit
 autom4te.cache 2012-07-28 ssjtoma [r2] Initial commit
 branches 2012-07-26 allura [r1] Initial commit
 m4 2012-07-28 ssjtoma [r2] Initial commit
 src 2012-07-28 ssjtoma [r2] Initial commit
 tags 2012-07-26 allura [r1] Initial commit
 trunk 2012-10-16 ssjtoma [r6] Queue empty and all jobs done signals.
 Makefile 2012-07-28 ssjtoma [r2] Initial commit
 Makefile.am 2012-07-28 ssjtoma [r2] Initial commit
 Makefile.in 2012-07-28 ssjtoma [r2] Initial commit
 README 2012-07-28 ssjtoma [r2] Initial commit
 aclocal.m4 2012-07-28 ssjtoma [r2] Initial commit
 config.guess 2012-07-28 ssjtoma [r2] Initial commit
 config.h 2012-07-28 ssjtoma [r2] Initial commit
 config.h.in 2012-07-28 ssjtoma [r2] Initial commit
 config.log 2012-07-28 ssjtoma [r2] Initial commit
 config.status 2012-07-28 ssjtoma [r2] Initial commit
 config.sub 2012-07-28 ssjtoma [r2] Initial commit
 configure 2012-07-28 ssjtoma [r2] Initial commit
 configure.ac 2012-07-28 ssjtoma [r2] Initial commit
 depcomp 2012-07-28 ssjtoma [r2] Initial commit
 install-sh 2012-07-28 ssjtoma [r2] Initial commit
 libtool 2012-07-28 ssjtoma [r2] Initial commit
 ltmain.sh 2012-07-28 ssjtoma [r2] Initial commit
 missing 2012-07-28 ssjtoma [r2] Initial commit
 stamp-h1 2012-07-28 ssjtoma [r2] Initial commit

Read Me

Author: Tamas K Lengyel, Johan Hanssen Seferidis
Created: 2011-08-12
Updated: 2012-7-26


=================================== Compiling =====================================

  ./configure
  make
  make check

  (optionally) make install


====================================== Linking =====================================

If you want to link with the library, pass the -lthpool flag to your compiler.

For example: gcc mycode.c -lthpool -lpthread -o myprogram

====================================== Usage  ======================================

1. Make a thread pool:                       thpool_t* thpool;
2. Initialise the thread pool with number
   of threads(workers) you want:             thpool=thpool_init(4);
3. Add work to the pool:                     thpool_add_work(thpool, (void*)doSth, (void*)arg);
4. Destroy pool:                             thpool_destroy(thpool);

=============================== Threadpool Interface ===============================


NAME
     thpool_t* thpool_init(int num_of_threads);

SYNOPSIS
  
     #include <thpool.h>

     thpool_t* thpool_init(int num_of_threads);

DESCRIPTION

     Initialises the threadpool. On success a threadpool structure is returned. Otherwise if memory could not be allocated NULL is returned. The argument which is the number of threads in the threadpool should be a thoughfull choice. A common suggestion is to use as many threads as the ones supported by your cpu.

     Example:
     thpool_t* myThreadpool;                 //First we declare a threadpool
     myThreadpool=thpool_init(4);            //then we initialise it to 4 threads


-----------------------------------------------------------------------------------



NAME
     thpool_add_work(thpool_t* thpool, void *(*function_p)(void*), void* arg_p);

SYNOPSIS
  
     #include <thpool.h>

     int thpool_add_work(thpool_t* thpool, void *(*function_p)(void*), void* arg_p);

DESCRIPTION

     Adds work to the thread pool. Work is concidered an individual function with an argument. First argument is a pointer to the pool itself. The second argument is a pointer to a function and third argument is a pointer to an argument. To pass multiple arguments just use a struct. If the function you want to pass doesn't fit the parameters of this prototype, use casting. If your function or argument doesn't fit the parameters' and return's value type then you should use casting to avoid warnings from the compiler.

     Example:
     void printSth(char* str);                                 //Prints a text on the screen
     thpool_add_work(thpool, (void*)printSth, (void*)str, 0);  //Pay attention to the casting


-----------------------------------------------------------------------------------


NAME
     void thpool_destroy(thpool_t* tp_p);

SYNOPSIS
  
     #include <thpool.h>

     void thpool_destroy(thpool_t* tp_p);

DESCRIPTION

     This function will destroy a threadpool. If some threads are working in the pool then thpool_destroy() will wait for them to finish. Once they are finished the threadpool is deallocated releasing all resources back to the system.

     Example:
     thpool_destroy(threadpool_p);           //threadpool_p being a pointer to a thpool_t
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.