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.
How do I temporarily 'protect' a variable/object.
Re: How do I temporarily 'protect' a variable/object.
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.
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.
Re: How do I temporarily 'protect' a variable/object.
All ahk threads. Thanks. I'll try that.
Who is online
Users browsing this forum: Chunjee and 312 guests