<< Prev        Next >>

ID : 5038

Program Example 3 for Exclusion Control

This is an example of handling the case that the exclusion control is aborted by an error. It will be executed in Pro1-> Pro2 order and controls exclusively to have I1, I2 and I3 in sequence number any time. When an error occurs, return processing will be executed to handle mismatched status.

'!TITLE "Program Example 3 for Exclusion Control"
' Program name "Pro1"
Sub Main

 Dim n as integer
 Dim id as integer
 id = CreateMutex( "Mutex-A" )

	For n = 3 To -3 Step -1
	 
	 TakeMutex id

	 'Make mismatched status by random digits
	 I1 = rnd*100
	 I2 = rnd*100
	 I3 = rnd*100

	  Run Pro2

	  I1 = 1
	  I2 = 2

	  ' Create a pseudo mismatched status as a result of error occurrence
	  I0 = I0 / n ' Zero rate, error changes Mutex object's status to error status

	  I3 = 3

	 GiveMutex id
	 
	Next

 ' Take sequential number from I1

 DeleteMutex id

End Sub
'!TITLE "Program Example 3 for Exclusion Control"
' Program name "Pro2"
Sub Main

 Dim id as integer
 id = CreateMutex( "Mutex-A" )

 On Error Goto MutexErr

 TakeMutex id ' When Mutex object is in error status, an error occurs

  PrintDbg I1, I2, I3 'Should take sequential number

 GiveMutex id

 DeleteMutex id

 Exit Sub

MutexErr:

 'Set to the matched status (an example)
  I1 = 1
  I2 = 2
  I3 = 3
 
 ResetMutex id 'Reset error status
 Resume 'Retry from the point where the error occurs

End Sub

ID : 5038

<< Prev        Next >>