As I reviewed the win32/sema.c, there is some code that I am not clear, can anybody explain please?
In semctl(SETVAL): if (semun.val < sem_counts[semNum]) sops.sem_op = -1; else sops.sem_op = 1; /* Quickly lock/unlock the semaphore (if we can) */ if (semop(semId, &sops, 1) < 0) return -1; When semun.val < sem_counts[semNum], it means we want to set the semaphore to semun.val, but because somebody ReleaseSemaphore() for serveral times, so we should wait for this semaphore several times (i.e., sem_counts[semNum] - semun.val) to recover it. When semun.val > sem_counts[semNum], we should ReleaseSemaphore() serveral times to recovery it. That is, should the sem_op assignment logic be: sops.sem_op = semun.val - sem_counts[semNum]; Of course, this would require we add a loop logic in semop(). Regards, Qingqing ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org