|
From: Frank V. C. <fr...@co...> - 2000-08-22 12:50:17
|
Hans Dulimarta wrote:
>
> Frank encouraged me to keep asking question and now I do :-).
> I am trying to understand the SemaphoreCommon class and
> would like to ask the following questions:
>
> 1. Why CSA is needed? Is it used for obtaining the key of semget()?
> However, I also find SemaphoreGroup::tmpDir ("/tmp") and
> SemaphoreGroup::tmpName (/tmp/clsgtemp.\d+) used by ftok to generate
> the key, but I could not find the connection between CSA and ftok.
The CSA is the shared memory that libcorelinux library knows about and
relies on for enabling SemaphoreGroups to share the state of it's
semaphores BETWEEN two (2) or more processes. Without it, the state of a
semaphore in one process would be out of synchronization with other
processes that are sharing the semaphore group.
> 2. SemaphoreCommon defines members setLock and setUnLock which eventually
> calls the Dijkstra's P()/down() and V()/up() operation.
> To implement EventSemaphore, I am planning to use the "zero()"
> operation,
> that is semop with sembuf.sem_op set to 0.
> Will it be apropriate? If, yes, should a new member "setZero()" be added
> to SemaphoreCommon?
Adding a setZero() to the base semaphore is no problem, but remember to
extend it over to the CSA.
>
> I also have a couple of comments:
>
> 1. SemaphoreCommon::setLock and SemaphoreCommon::setUnLock call
> semop and pass 'ON' as the third actual parameter.
> Semantically, 'ON' does not make sense to the call because
> the third formal parameter of semop is 'number of semaphore operations'.
You may modify as you see fit. If you want to just run it by the mailing
list first with your decision, feel free.
>
> 2. I think the constant ON and OFF in SemaphoreCommon are overloaded
> for too many different context, in some cases sacrificing its semantics.
> For instance, the semantic of "-ON" [minus ON] is not clear.
You may modify as you see fit. :)
--
Frank V. Castellucci
http://corelinux.sourceforge.net
OOA/OOD/C++ Standards and Guidelines for Linux
http://PythPat.sourceforge.net
Pythons Pattern Package
|