Game Development Reference
In-Depth Information
CRITICAL_SECTION TheCS;
#else
mutable pthread_mutex_t TheMutex;
#endif
};
How it works...
Using the Resource Acquisition Is Initialization (RAII) C++ idiom, we can deine the
Lock
class:
class Lock
{
public:
explicit Lock( const clMutex* Mutex ) : FMutex( Mutex )
{ FMutex->Lock(); };
~Lock() { FMutex->Unlock(); };
private:
const Mutex* FMutex;
};
Then, using mutexes is straightforward:
Lock( &SomeMutex );
We use mutexes extensively almost everywhere in the subsequent chapters of this topic.
See also
F
Implementing asynchronous task queues
Managing memory using reference counting
When working in the native code environment, every memory allocation event is handled
by the developer. Tracking all the allocations in a multithreaded environment becomes
notoriously dificult. The C++ language provides a way to avoid manual object deallocation
using smart pointers. Since we are developing mobile applications, we cannot afford to use
the whole Boost library just to include smart pointers.