<< Prev        Next >>

ID : 5164

MutexState

Function

To return the status of Mutex object.

Syntax

MutexState(MutexID)

Guaranteed entry

MutexID
Designate the ID of Mutex object by integer type data.

Return value

Return integer type data which shows the status of the designated Mutex object.

Description

Return the status of Mutex object.

Return value
Return value Status
-1 There is no Mutex object with the designated id.
0 Mutex object's status is "Unlocked."
1 Mutex object's status is "Locked." (Own task is Locked.)
2 Mutex object's status is "Locked." (Another task is Locked.)
65536(&H10000) Mutex object's status is "Unlocked" and in error status.
65537(&H10001) Mutex object's status is "Locked" and in error status. (Own task is Locked.)
65538(&H10002) Mutex object's status is "Locked" and in error status. (Another task is Locked.)

In the case of error status, +65536(&H10000) will be done.

Attention

Example

Mutex does not support nest. This is an avoidance example within a called process.

Execute a common process "FuncA" in Pro1. Call FuncA which is exclusively controlled in the exclusion control of Pro1. TakeMutex in FuncA has been Locked in Pro1, so nothing will happen on it. GiveMutex in FuncA is to be Unlocked, so it is alternative depending on the condition before TakeMutex in FuncA.

<Pros1.pcs>

#Include "FancA.pcs"
Sub Main
	Dim id As Integer
	id = CreateMutex(S[10])
	TakeMutex id
	Call FuncA(id)
	' statements
	GiveMutex id
End Sub

<FuncA.pcs>

Common process

Sub FuncA(ByVal id As Integer)
	Dim iState As Integer
	iState = MutexState(id)
	TakeMutex id
	'Statements
	If iState <> 1 Then
		GiveMutex id 
	End If
End Sub

ID : 5164

<< Prev        Next >>