How do I temporarily 'protect' a variable/object.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gbrao
Posts: 7
Joined: 18 Aug 2018, 22:43

How do I temporarily 'protect' a variable/object.

20 Aug 2018, 00:51

I have a array that is accessed/updated by more than one thread/function. Some functions are invoked on events. One function is invoked every nn minutes to back up that array to disk.

I want to ensure only one function/thread can access that array at a time. If the array is in 'use', the function should wait.

I think the correct term is semaphore.
YMP2
Posts: 48
Joined: 20 Apr 2014, 06:55

Re: How do I temporarily 'protect' a variable/object.

20 Aug 2018, 06:07

Are your threads real threads, or AutoHotkey threads that simply interrupt one another?

Perhaps you could use the message queue of AutoHotkey for this synchronization by sending messages to its hidden window. Every function that uses the array would send a request message before its use and a release message after. The function handling the messages would return True if the array was free and mark it as used until it received the release message. If the array was being used, it would return False to the request sender.
gbrao
Posts: 7
Joined: 18 Aug 2018, 22:43

Re: How do I temporarily 'protect' a variable/object.

20 Aug 2018, 07:59

All ahk threads. Thanks. I'll try that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 312 guests