<< Prev        Next >>

ID : 5037

Program Example 2 for Exclusion Control

This is an example of exclusion control between tasks aware of lifetime of the Mutex object. It will be executed in Pro1-> Pro2-> Pro3 order. Lifetime of Mutex object depends on Pro1.

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

 Dim id as integer

 id = CreateMutex( “Blocking-Section” )

 TakeMutex id
 Run Pro2
 Run Pro3

  TakeMutex id

	For I1 =1 To 10
	  PrintDbg “pro1 - ” & I1
	  Delay 100
	Next 

  GiveMutex id

 Wait MutexState(id) = 0  ‘ Wait until completion of all processes
 DeleteMutex id

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

 Dim id as integer

 id = MutexID( “Blocking-Section” )

  TakeMutex id

	For I1 =1 To 10
	  PrintDbg “pro2 - ” & I1
	  Delay 100
	Next 

  GiveMutex id

End Sub
'!TITLE "Program Example 2 for Exclusion Control"
' Program name "Pro3"
Sub Main

 Dim id as integer

 id = MutexID( “Blocking-Section” )

  TakeMutex id

	For I1 =1 To 10
	  PrintDbg “pro3 - ” & I1
	  Delay 100
	Next 

  GiveMutex id

End Sub

ID : 5037

<< Prev        Next >>