next up previous contents
Next: Internal vs. External Up: Reference counts Previous: Counting External References

Counting xPops

 

To understand the second component of the reference count, the number of outstanding xPops on a session, it is important to realize that a protocol does not have explicit references to its own sessions. That is, while a protocol usually maintains pointers to its sessions (in a map) and invokes operations on them, the sessions' reference counts do not take these pointers into account. (This is why xCreateSessn returns an object with a reference count of 0 and not 1.)

For a protocol to safely send this session pointer outside of the protocol (e.g., as a parameter in xDemux), it needs to turn the pointer into a reference by incrementing the session's reference count. It could do this by calling xDuplicate on the session as soon as it is extracted from the session map, making the external call, and then closing the session. But since all protocols must do this for incoming messages, this functionality has been absorbed into xPop, that is, xPop increments the reference count of the session before calling the pop function and decrements it (possibly calling the session's close operation) afterwards.

It could be argued that all UPI functions, not just xPop, should indicate their use of a session by incrementing the reference count at their start and decrementing it at their completion. To perform any other UPI operation on a session, however, you must already have a reference to that session. As long as an xClose is not performed on that reference, the session is not going to go away; maintaining reference counts for these operations is not necessary. xPops are different in that a session's reference count does not reflect that its protocol may send messages up through it.

Note that reference counts will not help a protocol which performs an xClose on a session reference while another thread has an outstanding operation on that same reference. To perform such a sequence is a protocol error. If two threads share a session reference, they should either synchronize to avoid such sequences or they should duplicate the reference with xDuplicate and each thread should xClose its reference when it is through.



next up previous contents
Next: Internal vs. External Up: Reference counts Previous: Counting External References



Larry Peterson
Wed Feb 21 13:58:06 MST 1996