Question on win32 semaphore simulation

Поиск
Список
Период
Сортировка
От Qingqing Zhou
Тема Question on win32 semaphore simulation
Дата
Msg-id e1fm7e$2gb4$1@news.hub.org
обсуждение исходный текст
Список 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




В списке pgsql-hackers по дате отправления:

Предыдущее
От: David Fetter
Дата:
Сообщение: Re: psql -p 5433; create database test; \c test failing
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: plpgsql by default