Difference between revisions of "MC-Basic:SEMAPHORETAKE"
m (Text replace - "Versions 3.7.x and higher" to "Since Version 3.7.x") |
|||
Line 57: | Line 57: | ||
|SEE ALSO= | |SEE ALSO= | ||
− | * [[ | + | * [[MC-Basic:SEMAPHOREGIVE|SEMAPHOREGIVE]] |
[[Category:Axystems:MC-Basic:Semaphore Handling|SEMAPHORETAKE]] | [[Category:Axystems:MC-Basic:Semaphore Handling|SEMAPHORETAKE]] | ||
}} | }} |
Revision as of 08:40, 22 May 2014
SEMTAKE acquires a semaphore that can be used for multi-task synchronization. If a semaphore is free, SEMTAKE returns 1 and the semaphore is marked as ‘taken’. If the semaphore is already taken, SEMTAKE returns 0 and the semaphore’s status does not change. SEMTAKE can be used to block simultaneous access to shared resources in the system or to a critical user software section.
If time-out is provided system will try to acquire a semaphore specified amount of time.
Short form
semTake
Syntax
<lval> = SemTake(<semaphore name> { , <timeout>})
Availability
Since Version 3.7.x
Type
Long
Range
return value: 0 = unsuccessful (semaphore not taken)
1 = succeessful (semaphore taken)
<timeout>: 0 to 5000
Units
milliseconds
Default
0
Scope
Task, Terminal
Examples
While semTake(SEM1,1000) = 0 ‘wait for the release of the semaphore
’wait for resource
End While
REM critical section code
……
……
semTake(SEM1) ‘take the semaphore
semTake(SEM1 , 100 )