OpenVMS Source Code Demos
DEMO_LOCK_CEF.BAS
1000 %title "DEMO_LOCK_CEF_100.BAS"
%ident "version_1.00"
!========================================================================================================================
! Title : DEMO_LOCK_CEF_100.BAS
! Author : Neil Rieck
! Created: 00.04.03
! Purpose: to demonstrate the use of COMMON EVENT FLAGS for use as a method to control access to a shared resource
! Use : run 2 instances of this program from 2 terminals logged in with the same user id.
! Note : Clusters #0 and #1 are Local Event Flags (LEF) and may only be used by the same process to coordinate things
! like ASTs etc.
! : Clusters #2 and #3 are Common Event Flags (CEF) and may only be used by processes with the same UIC
!========================================================================================================================
option type=explicit
!
%nolist ! keep listing file small
%include "starlet" %from %library "sys$library:basic$starlet" ! system services
%include "$ssdef" %from %library "sys$library:basic$starlet" ! ss$
%list !
!
declare long rc% ,! return code &
c2_flags% !
!
print "-i-ascefc #2"
rc% = sys$ascefc(64%, "DEMO_LOCK_CEF_C2", 0%, 0%) ! associate with cluster #2, same group, temporary
print "-i-ascefc #2 rc:",str$(rc%)
!
loop:
print "-i-readef #64"
rc% = sys$readef(64%, c2_flags% ) ! test flag 64, but retrieve all flags
select rc%
case ss$_wasset
print "-i-was set"
case ss$_wasclr
print "-i-was clear"
case else
print "-e-readef #64 rc:",str$(rc%)
end select
!
! try to set the flag
!
print "-i-setef #64"
rc% = sys$setef( 64% )
select rc%
case ss$_wasset ! we didn't set it so loop back
print "-i-setef #64, was already set (bad)"
sleep 1
goto loop ! loop back (try again)
case ss$_wasclr
print "-i-setef #64, was previous clear (good)"
case else
print "-e-readef #64 rc:",str$(rc%)
end select
!
print "starting work (30 seconds)"
sleep 30 ! do some work
print "finished work"
!
print "-i-clref #64"
rc% = sys$clref( 64% )
select rc%
case ss$_wasset
print "-i-clref #64, was already set (good)"
case ss$_wasclr
print "-i-clref #64, was previous clear (bad)"
case else
print "-e-clref #64 rc:",str$(rc%)
end select
!
print "-i-dacefc #2"
rc% = sys$dacefc( 64% ) ! disassociate from cluster #2
print "-i-dacefc #2 rc:",str$(rc%)
!
end
Back to
Home
Neil Rieck
Waterloo, Ontario, Canada.