c-template
wait_group.h File Reference

provides C equivalent of Golang sync.Wait enables "signalling" multiple threads allows management of multiple threads, and enabling clean exits or cleanups it is a bit different than joining pthreads to wait for processes to exit as it doesn't require attached pthreads (can be used with detached) for synchronizatiion More...

#include <stdio.h>
#include <pthread.h>
Include dependency graph for wait_group.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  wait_group_t
 

Typedefs

typedef struct wait_group_t wait_group_t
 a simple structure of a pthread mutex and integer counter More...
 

Functions

void wait_group_add (wait_group_t *wg, int count)
 incremements the total number of active processes managed by this wait group More...
 
int wait_group_done (wait_group_t *wg)
 used by a process to indicate it is done, decreasing the active process counter we include a return code here to catch errors when trying to decrement count below 0 More...
 
void wait_group_wait (wait_group_t *wg)
 used to wait until current active_processes reaches 0, polling every 0.75 seconds will run free on the wait_group_t pointer to clear up resources More...
 
wait_group_twait_group_new ()
 returns a new and initialized wait_group_t pointer More...
 
void wait_group_recv_signal (wait_group_t *wg)
 
void wait_group_listen_signal (wait_group_t *wg)
 
void wait_group_send_signal (wait_group_t *wg)
 

Detailed Description

provides C equivalent of Golang sync.Wait enables "signalling" multiple threads allows management of multiple threads, and enabling clean exits or cleanups it is a bit different than joining pthreads to wait for processes to exit as it doesn't require attached pthreads (can be used with detached) for synchronizatiion

Author
Bonedaddy
Todo:
:
  • determine if this is more efficient than using thread joining
  • expand signalling capabilities to enable a channel

Definition in file wait_group.h.

Typedef Documentation

◆ wait_group_t

a simple structure of a pthread mutex and integer counter

Function Documentation

◆ wait_group_add()

void wait_group_add ( wait_group_t wg,
int  count 
)

incremements the total number of active processes managed by this wait group

Parameters
wgthe waitgroup to manipulate
countthe number of new active processes

Definition at line 64 of file wait_group.c.

Here is the caller graph for this function:

◆ wait_group_done()

int wait_group_done ( wait_group_t wg)

used by a process to indicate it is done, decreasing the active process counter we include a return code here to catch errors when trying to decrement count below 0

Precondition
wg->active_process must be greater than or equal to 1 otherwise return -1
Warning
in the future this may be changed so that calling wait_group_done with a 0 value active_processes will cause a program exit
Parameters
wgthe waitgroup to manipulate a runtime error will occur and program will exit
Returns
Failure: -1
Success: 0
Todo:
:
  • (bonedaddy) decide if we should do a runtime exit on pre condition failure

Definition at line 70 of file wait_group.c.

Here is the caller graph for this function:

◆ wait_group_listen_signal()

void wait_group_listen_signal ( wait_group_t wg)

◆ wait_group_new()

wait_group_t* wait_group_new ( )

returns a new and initialized wait_group_t pointer

Definition at line 9 of file wait_group.c.

Here is the caller graph for this function:

◆ wait_group_recv_signal()

void wait_group_recv_signal ( wait_group_t wg)

Definition at line 21 of file wait_group.c.

◆ wait_group_send_signal()

void wait_group_send_signal ( wait_group_t wg)

Definition at line 27 of file wait_group.c.

◆ wait_group_wait()

void wait_group_wait ( wait_group_t wg)

used to wait until current active_processes reaches 0, polling every 0.75 seconds will run free on the wait_group_t pointer to clear up resources

Parameters
wgthe waitgroup to wait on

Definition at line 45 of file wait_group.c.

Here is the caller graph for this function: