Sign in to follow this  
Followers 0
computerwiz

Semaphore/Mutex to synchronize multiple Processes

3 posts in this topic

Hi!

I've been wanting to synchronize multiple writer processes, all of which write some data into one file. But I've been unable to do so. Usually the error is that the processes are unable to access the object and sometimes an error occurs saying that "Handle is invalid".

I don't think the code is required for this. If someone could demonstrate a working method, that would be enough.

Could someone help me out?

Thanks

Share this post


Link to post
Share on other sites



Hi!

I've been wanting to synchronize multiple writer processes, all of which write some data into one file. But I've been unable to do so. Usually the error is that the processes are unable to access the object and sometimes an error occurs saying that "Handle is invalid".

I don't think the code is required for this. If someone could demonstrate a working method, that would be enough.

Could someone help me out?

Thanks

A simple example for semaphores.

#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

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

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

_WinAPI_WaitForSingleObject($hSemaphore)
_MyGUI()
_WinAPI_ReleaseSemaphore($hSemaphore)
_WinAPI_FreeHandle($hSemaphore)

Func _MyGUI()

    Local $Msg

    GUICreate('MyGUI')
    GUISetState()
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_MyGUI

WinAPIEx.au3

Share this post


Link to post
Share on other sites

Thanks a lot for your help!! :D And might I say its real simple than the mess of a code I've been doing.

Thanks again. Cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0