Class threadable

Class Documentation

class threadable

Daemon interface class which can be derived from to indicate that the class can spawn a new thread and jump into the main loop defined for the class.

Public Functions

threadable(const threadable&) = delete
threadable(void) = default
virtual ~threadable(void) = default
inline void join(void)

Join a thread (i.e. wait for it to finish).

threadable &operator=(const threadable&) = delete
status_t start(void *arg, int core = -1)

Start a thread.

Parameters:
  • arg – Argument passed to thread (can be NULL).

  • core – The core to bind the thread to. By default, the thread is unbound.

Returns:

status_t - OK if successful, ERROR otherwise

inline virtual void term(void)

Signal a thread that it should terminate, from outside the thread.

virtual void *thread_main(void *arg) = 0

The entry point for a thread.

Parameters:

arg – Argument passed to thread (can be NULL).

Returns:

The return value of the thread.

Protected Functions

inline void exit(void *ret = nullptr)

Exit a thread from within the thread itself.

Parameters:

ret – If non-NULL, will be filled with the return value of the thread as it exits.

inline bool terminated(void) const

Check if a thread object has been told to terminate elsewhere.

inline pthread_t thread_handle(void) const

Get the pthread handle for the thread.

Returns:

The handle.

inline int64_t thread_id(void) const

Get the ID of the thread within the parent process.

Returns:

The thread ID (guaranteed to be unique among threads in a process).