Examples added

This commit is contained in:
Johan 2015-01-17 20:18:17 +00:00
parent f5edcd6477
commit 49e7851a69
1 changed files with 55 additions and 0 deletions

View File

@ -21,6 +21,10 @@ typedef struct thpool_* threadpool;
* Initializes a threadpool. This function will not return untill all * Initializes a threadpool. This function will not return untill all
* threads have initialized successfully. * threads have initialized successfully.
* *
* @example
* threadpool thpool; //First we declare a threadpool
* thpool = thpool_init(4); //then we initialize it to 4 threads
*
* @param num_threads number of threads to be created in the threadpool * @param num_threads number of threads to be created in the threadpool
* @return threadpool created threadpool on success, * @return threadpool created threadpool on success,
* NULL on error * NULL on error
@ -37,6 +41,20 @@ threadpool thpool_init(int num_threads);
* *
* NOTICE: You have to cast both the function and argument to not get warnings. * NOTICE: You have to cast both the function and argument to not get warnings.
* *
* @example
*
* void print_num(int num){
* printf("%d\n", num);
* }
*
* int main() {
* threadpool thpool = thpool_init(4);
* int a = 10;
* thpool_add_work(thpool, (void*)print_num, (void*)a);
* thpool_wait(thpool);
* return 0;
* }
*
* @param threadpool threadpool to which the work will be added * @param threadpool threadpool to which the work will be added
* @param function_p pointer to function to add as work * @param function_p pointer to function to add as work
* @param arg_p pointer to an argument * @param arg_p pointer to an argument
@ -54,6 +72,17 @@ int thpool_add_work(threadpool, void *(*function_p)(void*), void* arg_p);
* *
* Polling is used in wait. By default the polling interval is one second. * Polling is used in wait. By default the polling interval is one second.
* *
* @example
* int main() {
* threadpool thpool1 = thpool_init(4);
* ..
* // Add a bunch of work
* ..
* thpool_wait(thpool);
* puts("All added work has finished");
* return 0;
* }
*
* @param threadpool the threadpool to wait for * @param threadpool the threadpool to wait for
* @return nothing * @return nothing
*/ */
@ -69,6 +98,15 @@ void thpool_wait(threadpool);
* *
* While the thread is being paused, new work can be added. * While the thread is being paused, new work can be added.
* *
* @example
*
* threadpool thpool = thpool_init(4);
* thpool_pause(thpool);
* ..
* // Add a bunch of work
* ..
* thpool_resume(thpool); // Let the threads start their magic
*
* @param threadpool the threadpool where the threads should be paused * @param threadpool the threadpool where the threads should be paused
* @return nothing * @return nothing
*/ */
@ -78,6 +116,13 @@ void thpool_pause(threadpool);
/** /**
* @brief Unpauses all threads if they are paused * @brief Unpauses all threads if they are paused
* *
* @example
* ..
* thpool_pause(thpool);
* sleep(10); // Delay execution 10 seconds
* thpool_resume(thpool);
* ..
*
* @param threadpool the threadpool where the threads should be unpaused * @param threadpool the threadpool where the threads should be unpaused
* @return nothing * @return nothing
*/ */
@ -90,6 +135,16 @@ void thpool_resume(threadpool);
* This will wait for the currently active threads to finish and then 'kill' * This will wait for the currently active threads to finish and then 'kill'
* the whole threadpool to free up memory. * the whole threadpool to free up memory.
* *
* @example
* int main() {
* threadpool thpool1 = thpool_init(2);
* threadpool thpool2 = thpool_init(2);
* ..
* thpool_destroy(thpool1);
* ..
* return 0;
* }
*
* @param threadpool the threadpool to destroy * @param threadpool the threadpool to destroy
* @return nothing * @return nothing
*/ */