The mxDestory() function will destroy a MUTEX variable.
After the call to mxDestroy(), the mutex variable cannot be used in further operations.
Input:
mx : MUTEX
The mutex to destroy.
Returns: INT
0
|
Mutex is destroyed.
|
1
|
Mutex is not initialized.
|
2
|
Mutex is busy.
|
Declaration:
FUNCTION mxDestroy : INT;
VAR_INPUT
mx : MUTEX;
END_VAR;
Example:
INCLUDE rtcu.inc
THREAD_BLOCK Thread;
VAR_INPUT
mx : MUTEX;
...
END_VAR;
...
WHILE mxStatus(mx:=mx) <> 1 DO
...
END_WHILE;
END_THREAD_BLOCK;
PROGRAM MutexTest;
VAR
mx : MUTEX;
th : ARRAY[1..3] OF Thread;
i : INT;
...
END_VAR;
mx := mxInit();
IF mxStatus(mx:=mx) = 1 THEN DebugMsg(message:="mxCnt failed to init!"); END_IF;
FOR i := 1 TO 3 DO th[i](mx:=mx,...); END_FOR;
...
BEGIN
...
IF mxStatus(mx:=mx) <> 1 THEN
...
END_IF;
...
IF ... THEN
WHILE mxDestroy(mx:=mx) = 2 DO END_WHILE;
END_IF;
...
END;
END_PROGRAM;
|