RTI Connext Traditional C++ API Version 7.2.0
DDSThreadFactory Class Referenceabstract

<<extension>> <<interface>> Interface for providing the threads needed by the middleware. It consists of operations to create and delete threads. The interface depends on the DDSThreadFactory_OnSpawnedFunction that specifies the operation to run in the new thread. More...

Inherited by NDDSStackManagedThreadFactory.

Public Member Functions

virtual void * create_thread (const char *thread_name, const struct DDS_ThreadSettings_t &settings, DDSThreadFactory_OnSpawnedFunction on_spawned, void *thread_param)=0
 Handles the creation of new threads. More...
 
virtual void delete_thread (void *thread)=0
 Handles the deletion of threads previously created by this factory. More...
 

Detailed Description

<<extension>> <<interface>> Interface for providing the threads needed by the middleware. It consists of operations to create and delete threads. The interface depends on the DDSThreadFactory_OnSpawnedFunction that specifies the operation to run in the new thread.

Member Function Documentation

◆ create_thread()

virtual void * DDSThreadFactory::create_thread ( const char *  thread_name,
const struct DDS_ThreadSettings_t settings,
DDSThreadFactory_OnSpawnedFunction  on_spawned,
void *  thread_param 
)
pure virtual

Handles the creation of new threads.

This callback is called by the middleware whenever it needs to create a new thread. The operation creates a new thread of control that will call the function specified by DDSThreadFactory_OnSpawnedFunction. On success, this operation must guarantee that after return the new thread of control been spawned and its execution has started or will start some time after.

The DDSThreadFactory_OnSpawnedFunction, function must be called in the new thread and return its value on finalization. The function should be called as follows:

void * thread_out = on_spawned(thread_params);
...
return thread_out;

Some thread frameworks do this directly by just receiving the function and its parameters as arguments on thread creation. For instance, POSIX follows this model when creating a thread and the start_routine function has the same signature as DDSThreadFactory_OnSpawnedFunction, so the parameter can be passed directly:

int result = pthread_create(&pthread_handle, &attr, on_spawned, thread_params);
...
return &pthread_handle;

◆ delete_thread()

virtual void DDSThreadFactory::delete_thread ( void *  thread)
pure virtual

Handles the deletion of threads previously created by this factory.

This callback is called by the middleware whenever it needs to delete a thread. This operation deletes a thread previously created via a call to DDSThreadFactory::create_thread on the same factory object. On success, the thread must be deleted but it does not have to guarantee that the execution has finished. Likewise, resources associated with the underlying operating system may be still in use. Depending on the thread framework, resources allocated on thread creation are released upon thread finalization. POSIX follows this model so no actions are required on the thread handle returned by pthread_create().