Colobot
|
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 () |
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.