From: | "Qingqing Zhou" <zhouqq(at)cs(dot)toronto(dot)edu> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Question on win32 semaphore simulation |
Date: | 2006-04-11 07:31:44 |
Message-ID: | e1fm7e$2gb4$1@news.hub.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2006-04-11 08:07:04 | Re: plpgsql by default |
Previous Message | David Fetter | 2006-04-11 06:16:14 | Re: psql -p 5433; create database test; \c test failing |