Function Reference


_WinAPI_ReleaseSemaphore

Increases the count of the specified semaphore object by a specified amount

#include <WinAPIProc.au3>
_WinAPI_ReleaseSemaphore ( $hSemaphore [, $iIncrease = 1] )

Parameters

$hSemaphore Handle to the semaphore object. The _WinAPI_CreateSemaphore() or _WinAPI_OpenSemaphore() function
returns this handle.
$iIncrease [optional] The amount by which the semaphore object's current count is to be increased. The value must be greater
than zero. If the specified amount would cause the semaphore's count to exceed the maximum count that
was specified when the semaphore was created, the count is not changed and the function returns 0. Default is 1.

Return Value

Success: The previous count for the semaphore.
Failure: Sets the @error flag to non-zero, call _WinAPI_GetLastError() to et extendd error information.

Remarks

The state of a semaphore object is signaled when its count is greater than zero and nonsignaled when its count
is equal to zero. The process that calls the _WinAPI_CreateSemaphore() function specifies the semaphore's initial
count. Each time a waiting process is released because of the semaphore's signaled state, the count of the
semaphore is decreased by one.

Related

_WinAPI_CreateSemaphore, _WinAPI_OpenSemaphore

See Also

Search ReleaseSemaphore in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>

If Not @Compiled Then
    MsgBox($MB_SYSTEMMODAL, '', 'To run this script, you must first compile it and then run the (.exe) file.')
    Exit
EndIf

Local $hSemaphore = _WinAPI_CreateSemaphore('MySemaphore', 2, 2)

_WinAPI_WaitForSingleObject($hSemaphore)
_MyGUI()
_WinAPI_ReleaseSemaphore($hSemaphore)
_WinAPI_CloseHandle($hSemaphore)

Func _MyGUI()
    GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'))
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_MyGUI