BEEP-8 SDK 1.0.0
Loading...
Searching...
No Matches
pthread.h File Reference

Header file for POSIX thread (pthread) functions. More...

#include <b8/os.h>
#include <b8/type.h>
#include <b8/sched.h>

Go to the source code of this file.

Classes

struct  _b8_pthread_attr_t
 

Macros

#define pthread_attr_t   b8_pthread_attr_t
 
#define PTHREAD_STACK_MIN   (0x200)
 
#define PTHREAD_CREATE_JOINABLE   0
 
#define PTHREAD_CREATE_DETACHED   1
 
#define pthread_equal(t1, t2)
 

Typedefs

typedef b8OsPid pthread_t
 
typedef void * pthread_addr_t
 
typedef pthread_addr_t(* pthread_startroutine_t) (pthread_addr_t)
 
typedef pthread_startroutine_t pthread_func_t
 
typedef struct _b8_pthread_attr_t b8_pthread_attr_t
 

Functions

int pthread_create (pthread_t *thread, const pthread_attr_t *attr, pthread_startroutine_t startroutine, pthread_addr_t arg)
 Creates a new thread.
 
int pthread_yield (void)
 Yields the processor to another thread.
 
pthread_t pthread_self (void)
 Returns the thread identifier of the calling thread.
 
int pthread_attr_init (pthread_attr_t *attr)
 Initializes a thread attributes object.
 
int pthread_attr_destroy (pthread_attr_t *attr)
 Destroys a thread attributes object.
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 Sets the stack size attribute in the thread attributes object.
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 Gets the stack size attribute from the thread attributes object.
 
int pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, long stacksize)
 Sets the stack address and size attributes in the thread attributes object.
 
int pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, long *stacksize)
 Gets the stack address and size attributes from the thread attributes object.
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 Gets the detach state attribute from the thread attributes object.
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 Sets the detach state attribute in the thread attributes object.
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)
 Sets the scheduling parameters in the thread attributes object.
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)
 Retrieves the scheduling parameters from the thread attributes object.
 
int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)
 Retrieves the scheduling policy and parameters of the specified thread.
 
int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)
 Sets the scheduling policy and parameters of the specified thread.
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 Sets the scheduling policy attribute in the thread attributes object.
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 Retrieves the scheduling policy from the thread attributes object.
 
void pthread_exit (pthread_addr_t value)
 Terminates the calling thread.
 
int pthread_detach (pthread_t thread)
 Detaches the specified thread.
 
int pthread_join (pthread_t thread, pthread_addr_t *value)
 Waits for the specified thread to terminate.
 
int pthread_cancel (pthread_t thread)
 Cancels the specified thread.
 
int pthread_setcanceltype (int type, int *oldtype)
 Sets the cancelability type of the calling thread.
 
void pthread_testcancel (void)
 Creates a cancellation point in the calling thread.
 

Detailed Description

Header file for POSIX thread (pthread) functions.

This header file provides the declarations for various POSIX thread (pthread) functions. It includes functions for creating and managing threads, setting and getting thread attributes, and handling thread scheduling and synchronization. The functionality of these functions varies based on the specific OS environment.

  • The following functions are fully supported and work correctly in this BEEP-8 environment:
    • pthread_create
    • pthread_yield
    • pthread_self
    • pthread_attr_init
    • pthread_attr_destroy
    • pthread_attr_setstacksize
    • pthread_attr_getstacksize
    • pthread_attr_setstack
    • pthread_attr_getstack
    • pthread_attr_getdetachstate
    • pthread_attr_setdetachstate
  • The following functions are not supported in this OS environment and always return -ERRNOSYS:
    • pthread_getschedparam
    • pthread_setschedparam
    • pthread_detach
    • pthread_join
    • pthread_cancel
    • pthread_setcanceltype
    • pthread_testcancel
  • The following functions can be called and will set attributes, but the actual scheduling policy or affinity settings are ignored in this BEEP-8 environment, making them effectively unsupported:
    • pthread_attr_setschedpolicy
    • pthread_attr_getschedpolicy
    • pthread_attr_setschedparam
    • pthread_attr_getschedparam
    • pthread_attr_setinheritsched
    • pthread_attr_getinheritsched
    • pthread_attr_setaffinity_np
    • pthread_attr_getaffinity_np

Macro Definition Documentation

◆ pthread_equal

#define pthread_equal ( t1,
t2 )
Value:
((t1) == (t2))

Function Documentation

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t * attr)
extern

Destroys a thread attributes object.

This function is part of the POSIX standard and is used to destroy a thread attributes object, freeing any resources it may hold. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object to be destroyed.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t * attr,
int * detachstate )
extern

Gets the detach state attribute from the thread attributes object.

This function is part of the POSIX standard and is used to retrieve the detach state attribute from a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
detachstateA pointer to a variable where the detach state will be stored.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_getschedparam()

int pthread_attr_getschedparam ( const pthread_attr_t * attr,
struct sched_param * param )
extern

Retrieves the scheduling parameters from the thread attributes object.

This function is part of the POSIX standard and allows retrieving the scheduling parameters from the thread attributes object. However, in this specific OS environment, while the function can be called and the parameters can be retrieved, the actual scheduling policy is ignored, making it effectively unsupported.

Parameters
attrA pointer to the thread attributes object.
paramA pointer to a struct sched_param where the scheduling parameters will be stored.
Returns
0 indicating success, but note that the retrieved scheduling policy is ignored.

◆ pthread_attr_getschedpolicy()

int pthread_attr_getschedpolicy ( const pthread_attr_t * attr,
int * policy )
extern

Retrieves the scheduling policy from the thread attributes object.

This function is part of the POSIX standard. In this specific environment, while the function can be called and the policy can be retrieved, the actual scheduling policy is ignored and thus effectively unsupported.

Parameters
attrA pointer to the thread attributes object.
policyA pointer to an integer where the policy will be stored.
Returns
0 indicating success, but note that the retrieved policy is ignored in practice.

◆ pthread_attr_getstack()

int pthread_attr_getstack ( const pthread_attr_t * attr,
void ** stackaddr,
long * stacksize )
extern

Gets the stack address and size attributes from the thread attributes object.

This function is part of the POSIX standard and is used to retrieve the stack address and size attributes from a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
stackaddrA pointer to a variable where the stack address will be stored.
stacksizeA pointer to a variable where the stack size will be stored.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t * attr,
size_t * stacksize )
extern

Gets the stack size attribute from the thread attributes object.

This function is part of the POSIX standard and is used to retrieve the stack size attribute from a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
stacksizeA pointer to a variable where the stack size will be stored.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t * attr)
extern

Initializes a thread attributes object.

This function is part of the POSIX standard and is used to initialize a thread attributes object with default values. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object to be initialized.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t * attr,
int detachstate )
extern

Sets the detach state attribute in the thread attributes object.

This function is part of the POSIX standard and is used to set the detach state attribute in a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
detachstateThe detach state to be set.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_setschedparam()

int pthread_attr_setschedparam ( pthread_attr_t * attr,
const struct sched_param * param )
extern

Sets the scheduling parameters in the thread attributes object.

This function is part of the POSIX standard and allows setting the scheduling parameters in the thread attributes object. However, in this specific OS environment, while the function can be called and the parameters can be set, the actual scheduling policy is ignored, making it effectively unsupported.

Parameters
attrA pointer to the thread attributes object.
paramA pointer to a struct sched_param containing the scheduling parameters.
Returns
0 indicating success, but note that the scheduling policy is ignored.

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t * attr,
int policy )
extern

Sets the scheduling policy attribute in the thread attributes object.

This function is part of the POSIX standard. In this specific environment, while the function can be called and the policy can be set, the actual scheduling policy is ignored and thus effectively unsupported.

Parameters
attrA pointer to the thread attributes object.
policyThe new scheduling policy.
Returns
0 indicating success, but note that the policy is ignored.

◆ pthread_attr_setstack()

int pthread_attr_setstack ( pthread_attr_t * attr,
void * stackaddr,
long stacksize )
extern

Sets the stack address and size attributes in the thread attributes object.

This function is part of the POSIX standard and is used to set the stack address and size attributes in a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
stackaddrThe stack address to be set.
stacksizeThe stack size to be set.
Returns
0 on success, or an error code on failure.

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t * attr,
size_t stacksize )
extern

Sets the stack size attribute in the thread attributes object.

This function is part of the POSIX standard and is used to set the stack size attribute in a thread attributes object. This function works correctly in this OS environment.

Parameters
attrA pointer to the thread attributes object.
stacksizeThe stack size to be set.
Returns
0 on success, or an error code on failure.

◆ pthread_cancel()

int pthread_cancel ( pthread_t thread)
extern

Cancels the specified thread.

This function is part of the POSIX standard and is used to request the cancellation of a thread. However, in this OS environment, this function is not supported and always returns -ERRNOSYS.

Parameters
threadThe thread to be canceled.
Returns
-ERRNOSYS indicating that this function is not supported.

◆ pthread_create()

int pthread_create ( pthread_t * thread,
const pthread_attr_t * attr,
pthread_startroutine_t startroutine,
pthread_addr_t arg )
extern

Creates a new thread.

This function is part of the POSIX standard and is used to create a new thread. It initializes a new thread and makes it executable, running the specified start routine with the given argument. This function works correctly in this OS environment.

Parameters
threadA pointer to the thread identifier that will be returned.
attrA pointer to the thread attributes object that specifies attributes for the new thread. If NULL, default attributes are used.
startroutineThe routine that the new thread will execute.
argThe argument passed to the start routine.
Returns
0 on success, or an error code on failure.

◆ pthread_detach()

int pthread_detach ( pthread_t thread)
extern

Detaches the specified thread.

This function is part of the POSIX standard and is used to detach a thread, allowing its resources to be automatically reclaimed upon termination. However, in this OS environment, this function is not supported and always returns -ERRNOSYS.

Parameters
threadThe thread to be detached.
Returns
-ERRNOSYS indicating that this function is not supported.

◆ pthread_exit()

void pthread_exit ( pthread_addr_t value)
extern

Terminates the calling thread.

This function is part of the POSIX standard and allows for the termination of the calling thread. However, in this specific OS environment, thread termination is not supported. While the function can be called, it will only put the thread into an indefinite wait state, and the thread will not be released or cleaned up.

Parameters
valueThe exit status of the thread.

◆ pthread_getschedparam()

int pthread_getschedparam ( pthread_t thread,
int * policy,
struct sched_param * param )
extern

Retrieves the scheduling policy and parameters of the specified thread.

This function is part of the POSIX standard. However, in this specific environment, it is not supported and will always return -ERRNOSYS.

Parameters
threadThe thread whose scheduling parameters are to be retrieved.
policyA pointer to an integer where the policy will be stored.
paramA pointer to a struct sched_param where the scheduling parameters will be stored.
Returns
-ERRNOSYS as this function is not supported in this environment.

◆ pthread_join()

int pthread_join ( pthread_t thread,
pthread_addr_t * value )
extern

Waits for the specified thread to terminate.

This function is part of the POSIX standard and is used to wait for a thread to terminate and optionally retrieve its exit status. However, in this OS environment, this function is not supported and always returns -ERRNOSYS.

Parameters
threadThe thread to wait for.
valueA pointer to a location where the exit status of the thread will be stored.
Returns
-ERRNOSYS indicating that this function is not supported.

◆ pthread_self()

pthread_t pthread_self ( void )
extern

Returns the thread identifier of the calling thread.

This function is part of the POSIX standard and is used to obtain the thread identifier of the calling thread. This function works correctly in this OS environment.

Returns
The thread identifier of the calling thread.

◆ pthread_setcanceltype()

int pthread_setcanceltype ( int type,
int * oldtype )
extern

Sets the cancelability type of the calling thread.

This function is part of the POSIX standard and is used to set the cancelability type (deferred or asynchronous) of the calling thread. However, in this OS environment, this function is not supported and always returns -ERRNOSYS.

Parameters
typeThe new cancelability type.
oldtypeA pointer to an integer where the previous cancelability type will be stored.
Returns
-ERRNOSYS indicating that this function is not supported.

◆ pthread_setschedparam()

int pthread_setschedparam ( pthread_t thread,
int policy,
const struct sched_param * param )
extern

Sets the scheduling policy and parameters of the specified thread.

This function is part of the POSIX standard. However, in this specific environment, it is not supported and will always return -ERRNOSYS.

Parameters
threadThe thread whose scheduling parameters are to be set.
policyThe new scheduling policy.
paramA pointer to a struct sched_param containing the new scheduling parameters.
Returns
-ERRNOSYS as this function is not supported in this environment.

◆ pthread_testcancel()

void pthread_testcancel ( void )
extern

Creates a cancellation point in the calling thread.

This function is part of the POSIX standard and is used to create a cancellation point in the calling thread, allowing it to be canceled if a cancellation request is pending. However, in this OS environment, this function is not supported and does not perform any action.

◆ pthread_yield()

int pthread_yield ( void )
extern

Yields the processor to another thread.

This function is part of the POSIX standard and is used to yield the processor from the calling thread to another thread, allowing other threads to run. This function works correctly in this OS environment.

Returns
0 on success, or an error code on failure.