KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
kjb::Pthread_attr Class Reference

RAII class to manage an object of type kjb_pthread_attr_t. More...

#include <l_mt_pt_attr.h>

Public Member Functions

 Pthread_attr ()
 initialize a generic attribute object. More...
 
 ~Pthread_attr ()
 destroy an attribute object. More...
 
int setdetachstate (int state)
 set the detach flag. More...
 
int set_detached ()
 convenience synonym setdetachstate(KJB_PTHREAD_CREATE_DETACHED) More...
 
int getdetachstate (int *state)
 obtain the detach setting of this object. More...
 
 operator const kjb_c::kjb_pthread_attr_t * ()
 access thread attribute as const pointer. More...
 

Detailed Description

RAII class to manage an object of type kjb_pthread_attr_t.

The kjb_pthread sublibrary, which wraps the Posix pthread library, uses an object of type kjb_pthread_attr_t to describe the attributes of a thread. Thread attributes are its "detach state," its stack size, and other things. See pthread_attr_init(3). A single attribute object may be used on multiple threads.

The attribute object must be created and destroyed, thus this RAII class exists to manage those tasks. Objects of this class are not copyable or assignable.

Currently this class does not support all thread attribute options, but a developer is welcome to add new ones to the C library wrapper (l_mt) and add WRAPPED calls through this class. Please do not call pthreads functions directly – use the wrapped calls in kjb_c.

Example.

void* ha(void*) { for(int i=100; i--; ) puts("lol"); }
main() {
kjb_c::kjb_pthread_t tid;
kjb_c::kjb_pthread_create(*tid, a, ha, NULL);
// no need to join
return 0;
}

Constructor & Destructor Documentation

kjb::Pthread_attr::Pthread_attr ( )
inline

initialize a generic attribute object.

kjb::Pthread_attr::~Pthread_attr ( )
inline

destroy an attribute object.

Member Function Documentation

int kjb::Pthread_attr::getdetachstate ( int *  state)
inline

obtain the detach setting of this object.

Parameters
[out]statePointer to int into which the state is written
Returns
ERROR or NO_ERROR
Postcondition
*state contains KJB_PTHREAD_CREATE_JOINABLE if the thread is joinable, or KJB_PTHREAD_CREATE_DETACHED if not.
kjb::Pthread_attr::operator const kjb_c::kjb_pthread_attr_t * ( )
inline

access thread attribute as const pointer.

int kjb::Pthread_attr::set_detached ( )
inline

convenience synonym setdetachstate(KJB_PTHREAD_CREATE_DETACHED)

int kjb::Pthread_attr::setdetachstate ( int  state)
inline

set the detach flag.

Parameters
flagKJB_PTHREAD_CREATE_JOINABLE, KJB_PTHREAD_CREATE_DETACHED are the two valid values.
Returns
ERROR or NO_ERROR as appropriate
See Also
set_detached as a possibly more readable alternative

The documentation for this class was generated from the following file: