Let me know if you find any problems
AutoHotkey_H v2 tls changes
I have implemented proper multi-threading support for AutoHotkey_H v2 using thread local storage.
Source code and binaries can be found on github.
All you will need to use new multi-threading feature is AutoHotkey.exe from Win32w or x64w folder.
I have run some tests and it works quite good so far but I need your help as more testing is required. Any feedback is welcome
Changelog on github.
Source code and binaries can be found on github.
All you will need to use new multi-threading feature is AutoHotkey.exe from Win32w or x64w folder.
I have run some tests and it works quite good so far but I need your help as more testing is required. Any feedback is welcome
Example:New features wrote:
- Multi-threading is only available in AutoHotkey.exe (AutoHotkeySC.bin will be discontinued as we can compile AutoHotkey.exe)
- New thread can be started via build-in function ThreadID := NewThread(Script, cmdLine:="", Title:=""), included function ExeThread(script, cmdLine:="", Title:="") or included function ThreadObj := ThreadObj(Script, cmdLine:="", Title:=""). To load a script from file simply use thead:=ThreadObj("#include MyFile.ahk"). While NewThread() returns only the ThreadID, ExeThread() and ThreadObj() allows to interact with new thread
ExeThread has the same methods as AhkExported() plus ahkReady.
ThreadObj allows following methods.
Also in new thread you can access the parent thread that created the new thread via A_ParentThread object using same methods.Code: Select all
Result := thread.Call(FuncName, p*) IsLabel := thread.GoTo(LabelName) IsLabel := thread.Gosub(LabelName) FuncPtr := ThreadObj.FuncPtr(FuncName) LabelPtr := ThreadObj.LabelPtr(LabelName) Success := ThreadObj.Exec(Code) LinePtr := ThreadObj.AddScript(Code, execute:=0) LinePtr := ThreadObj.AddFile(File, execute := 0) thread.VarName := value MgBox % thread.VarName ThreadObj.ExitApp()
- The Hook exists only once, so all Hotkeys and Hotstrings as well as Input are shared to all threads, this way we get errors when a hotkey or hotstring exists in another thread already and even Input can be cancelled (ErrorLevel="NewInput") from another thread.
- Debugger was also improved to support multi-threading.
Code: Select all
myVar:="Hello AutoHotkey from new thread!"
If !thread:=ThreadObj("
(
test:=100
MsgBox `% A_ParentThread.myVar
A_ParentThread.GoSub("labeltest")
A_ParentThread.GoTo("labeltest")
MsgBox New thread finished auto-execution
::ahk::AutoHotkey
F2::MsgBox thread
F8::ExitApp
)","/ErrorStdOut"){
MsgBox Error Creating thread
ExitApp
}
AhkThread("MsgBox Message from AutoHotkey.dll thread")
MsgBox % "Content of Variable test in new thread: " thread.test
thread.test:=["AHK"]
MsgBox % "Content of test.1 in new thread: " thread.test.1
thread.Func("msgBox",0,"Hello %A_ScriptHwnd%`n",A_ScriptHwnd)
thread.Exec("MsgBox `% `"New thread A_ScriptHwnd: `" A_ScriptHwnd `"``nMain thread A_ScriptHwnd: `" " A_ScriptHwnd)
MsgBox Main thread finished auto-execution`nPress SHIFT + ESCAPE to exit.
F1::MsgBox main
F3::thread.ExitApp()
::ahkh::AutoHotkey_H
+Esc::ExitApp
LabelTest:
MsgBox % "Label " a_thisLabel " was called"
return