Colobot
Classes | Public Types | Public Member Functions | List of all members
CResourceOwningThread< Resource > Class Template Reference

Wrapper around SDL thread allowing passing of resources in safe manner. More...

#include <resource_owning_thread.h>

Public Types

using ResourceUPtr = std::unique_ptr< Resource >
 
using ThreadFunctionPtr = void(*)(ResourceUPtr)
 

Public Member Functions

 CResourceOwningThread (ThreadFunctionPtr threadFunction, ResourceUPtr resource, std::string name="")
 
void Start ()
 

Detailed Description

template<typename Resource>
class CResourceOwningThread< Resource >

Wrapper around SDL thread allowing passing of resources in safe manner.

This class is a workaround for passing ownership of resources in a safe manner to newly created threads. It takes a pointer to a function to call in new thread and a unique_ptr to resource which is to be passed to the new thread.

This is how it works:

It's a bit complicated, but that's the safe (thread-safe and exception-safe) way of doing this.


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