[Sqlrelay-discussion] statistics and shm access without semaphores
Brought to you by:
mused
From: Renat S. <sr...@st...> - 2009-11-12 13:55:32
|
I'm afraid I've found the cause of strange statistics look at this code in sqllistener.C : shmdata *ptr=(shmdata *)staticlistener->idmemory->getPointer(); ptr->statistics.forked_listeners--; If 2 processes simultaniously get access to shared memory and, for example, in this moment forked_listeners = 10, then they both decrease this value to 9 and put back to shared memory. As result would be 9 instead of 8. Solution ids obvious: semaphores should be used to access shared memory. For example: shmdata *ptr=(shmdata *)staticlistener->idmemory->getPointer(); sem_t *mutex=staticlistener->idmemory->getSemaphore(); sem_wait(mutex); ptr->statistics.forked_listeners--; sem_post(mutex); -- Renat Sabitov e-mail: sr...@st... Stack Soft jid: sr...@ja... |