Page 1 of 1

Mutexes

Posted: Wed May 06, 2020 5:20 pm
by m59noob
Could someone recommend specific resources and tutorials to read up on mutexes? I have never touched mutexes and am trying to understand the function InitInterfaceLocks() called by MainServer():

Code: Select all

void InitInterfaceLocks()
{
   muxServer = MutexCreate();

   quit = False;
   InitializeCriticalSection(&csQuit);

}

Mutex MutexCreate()
{
    return CreateMutex(NULL, FALSE, NULL);
 }

void InitializeCriticalSection(CRITICAL_SECTION *m)
{
  pthread_mutexattr_t attr;
  pthread_mutexattr_init(&attr);
  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);

  pthread_mutex_init(m, &attr);
}

Re: Mutexes

Posted: Wed May 06, 2020 8:49 pm
by EvilSibhod
A mutex is a flag used to prevent simultaneous access to resources.

While I could make up an analogy, there are plenty of examples here: many of which have good discussions and further reading details.
https://stackoverflow.com/questions/345 ... is-a-mutex