BASIC Moves Development Studio
06/2005
Danaher Motion
46 Rev
E
M-SS-005-03l
2.6.2. Synchronization
Semaphores
Synchronization semaphores are essential in producer-consumer
applications where task A prepares some data, while task B consumes it. In
this case, the semaphore may eliminate constant polling for ready data and
save considerable CPU resources.
Example of Producer:
‘ common shared syncSemaphore as semaphore
‘ defined in config.prg
‘ common shared globalA as long ‘ defined in
config.prg
Program
Dim dummy as long
‘ Semaphore is created as “full” - flush it before first use
dummy=semTake(syncSemaphore) ‘ no waiting
While 1
globalA=1 ‘ produce some data
semGive(syncSemaphore)
sleep (100)
End While
End program
Example of Consumer:
' common shared syncSemaphore as semaphore
' defined in config.prg
' common shared globalA as long ' defined in config.prg
Program
While 1
If SemTake(syncSemaphore,5000) = 1 Then
Print "A is "; globalA
End if
End While
End program
2. 7
V
IRTUAL
E
NTRY
S
TATION
V
irtual
E
ntry
S
tation (VES) allows a CLI-like approach to the system from
any task or library. VES permits access to virtually any system property. The
application developer must take into account that, in the contrast to regular
programs and libraries, the string is passed to VES and are interpreted and
translated at run-time. Execution takes much more time than the equivalent
line in the program.
The response of VES is ASCII an string, which could be immediately printed
or assigned to any string variable. Since VES involves translation and then
interpretation, the result could also be an error message. To distinguish
between a normal response and an error, VES gives either a “D:” or “E:”
prefix to the output.