ID : 5037
排他处理的程序示例2
意识到Mutex对象存在期间任务之间的排斥处理示例。按照Pro1-> Pro2-> Pro3的顺序执行。Mutex对象存在期间依存于Pro1。
'!TITLE "排他处理的程序示例2"
' 程序名 "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 ‘ 等待直至全部结束
DeleteMutex id
End Sub
'!TITLE "排他处理的程序示例2"
' 程序名 "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 "排他处理的程序示例2"
' 程序名 "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