Page 2 of 3

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 12 Apr 2016, 11:35
by arcticir
Thanks.

I slightly modified: :)

Code: Select all

exethread(s:="",p:=""){
	return lib:=GetModuleHandle(),{(""):ThreadID:=NewThread(s,p)
	  ,_ahkFunction:DynaCall(GetProcAddress(lib,"ahkFunction"),"s==sttttttttttui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,_ahkPostFunction:DynaCall(GetProcAddress(lib,"ahkPostFunction"),"i==sttttttttttui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,ahkFunction:DynaCall(GetProcAddress(lib,"ahkFunction"),"s==sssssssssssui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,ahkPostFunction:DynaCall(GetProcAddress(lib,"ahkPostFunction"),"i==sssssssssssui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,addFile:DynaCall(GetProcAddress(lib,"addFile"),"ut==siui","",0,ThreadID)
	  ,addScript:DynaCall(GetProcAddress(lib,"addScript"),"ut==siui","",0,ThreadID)
	  ,ahkExec:DynaCall(GetProcAddress(lib,"ahkExec"),"ut==sui","",ThreadID)
	  ,ahkExecuteLine:DynaCall(GetProcAddress(lib,"ahkExecuteLine"),"ut==utuiuiui",0,0,0,ThreadID)
	  ,ahkFindFunc:DynaCall(GetProcAddress(lib,"ahkFindFunc"),"ut==sui","",ThreadID)
	  ,ahkFindLabel:DynaCall(GetProcAddress(lib,"ahkFindLabel"),"ut==sui","",ThreadID)
	  ,ahkgetvar:DynaCall(GetProcAddress(lib,"ahkgetvar"),"s==suiui","",0,ThreadID)
	  ,ahkassign:DynaCall(GetProcAddress(lib,"ahkassign"),"s==ssui","","",ThreadID)
	  ,ahkLabel:DynaCall(GetProcAddress(lib,"ahkLabel"),"ui==suiui","",0,ThreadID)
	  ,ahkPause:DynaCall(GetProcAddress(lib,"ahkPause"),"ui==sui","",ThreadID)
	  ,ahkIsUnicode:DynaCall(GetProcAddress(lib,"ahkIsUnicode"),"ui==")}
}

Code: Select all

	this.hThreadID:=NewThread("global A_ParentThread`nA_ParentThread(){`nstatic _:=A_ParentThread()`nA_ParentThread:=ObjShare(" ObjShare(new _ThreadClass) ")`nObjShare(" ObjShare(this) ").RegisterThread(ObjShare(ThreadObj_Class()))`n}`n" script,cmdLine)
look forward to solve memory problems .

-------------

Also, I have an idea I have said to you: to increase the definition of the title.
I found that for multi-threaded, it has a huge role.
It allows us to easily identify the thread.
For example, it is clear to know which thread pops up "MsgBox"

Code: Select all

NewThread(Script, cmdLine:="", title:="")
a_ahktitle
Although we can use GlobalStruct () modify it,
But it uses too much time.

-------------
Also, About thread parameters
In my experience, many threads need to pass parameters. Otherwise, it takes more time to take the initiative to get the data.
We can support it?
Its difficulty is to pass object parameters

Code: Select all

NewThread(Script, cmdLine:="", title:="", param:="")
a_ahkparam
For example the menu , it uses five threads. Parameter will reduce the interaction data.
Image

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 12 Apr 2016, 13:07
by nnnik
I'm not sure if you know about this already, but if the main Thread of AutoHotkey terminates before any of the children then we get a rather weird behavior.
But that brings up another Problem.
How are you going to handle Script Termination?

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 12 Apr 2016, 14:10
by HotKeyIt
I have improved ExeThread even more and implemented parameter for Title/A_ScriptName in newthread.

@nnnik: Main thread tries to exit all threads before exiting, if threads don't exit within around 1 second main threads terminates.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 12 Apr 2016, 17:51
by HotKeyIt
arcticir wrote:Also, About thread parameters
In my experience, many threads need to pass parameters. Otherwise, it takes more time to take the initiative to get the data.
We can support it?
Simply pass an object pointer or include the pointer in script.

Code: Select all

obj:=CriticalObject({test:"Hello World!"})
NewThread("obj:=CriticalObject(A_Args.1)`nMsgBox `% obj.test",(&obj) "","Test")
MsgBox end

Code: Select all

obj:=CriticalObject({test:"Hello World!"})
NewThread("obj:=CriticalObject(" (&obj) ")`nMsgBox `% obj.test",,"Test")
MsgBox end

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 13 Apr 2016, 00:30
by arcticir
I was so resolved, but I think some trouble. :D

I feel the need to make "A_ParentThread" having a "global and static" attribute .

Code: Select all

this.hThreadID:=NewThread("global A_ParentThread`nA_ParentThread(){`nstatic 
In order to avoid this situation :

Code: Select all

test(){
static x:=A_ParentThread.xxxx
}

@nnnik My method is more complicated. Using threads Console and PUM menu. But not difficult.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 13 Apr 2016, 05:23
by HotKeyIt
I have modified ExeThread() function to allow passing a threadID instead creating a Thread :)
Therefore the first parameter must be empty string and second parameter the threadID.

Code: Select all

var:="test"
NewThread("A_ParentThread:=ExeThread(`"`"," GetCurrentThreadId() ")`nMsgBox `% A_ParentThread.ahkgetvar.var")
MsgBox End

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 13 Apr 2016, 06:34
by arcticir
thanks.
Must be resolved , memory cleanup problem , otherwise all talk . :(

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 14 Apr 2016, 12:17
by arcticir
If this problem can not be resolved , then we only use AutoHotkey.dll approach. Reuse threads to save memory.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 15 Apr 2016, 13:37
by HotKeyIt
I have now fixed memory leaks and updated resource library functions ;)

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 16 Apr 2016, 07:37
by HotKeyIt
Fixed some bugs and added ahkReady support + ahkReady method to ExeThread().

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 17 Apr 2016, 17:51
by HotKeyIt
Update wrote:Improved exiting threads and added ahkterminate() method to exit thread created by ExeThread()

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 23 Apr 2016, 14:18
by HotKeyIt
New version is available, many bugs were fixed.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 25 Apr 2016, 09:17
by Barbossa155
oh nice
i replaced only the Autohotkey.exe from w64 folder

i tried your first example @ startpost and it says me something like

Image



what is to do?
thx

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 25 Apr 2016, 14:52
by HotKeyIt
There was a bug and example was not updated to use correct syntax, download new version and try new example from first post ;)

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 25 Apr 2016, 23:55
by HotKeyIt
I have changed back to use MSVCR100.dll for all modules and removed AutoHotkeySC.bin.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 28 Apr 2016, 16:14
by HotKeyIt
Implemented Reload for threads and invoking object from another thread.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 29 Apr 2016, 13:55
by HotKeyIt
I have implemented multi-threaded Objects and removed CriticalObject as there is no need for it anymore, the objects will be now always invoked in the thread which created them.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 07 May 2016, 05:53
by HotKeyIt
I have reverted and fixed CriticalObject() and fixed Title for NewThread as well as a fix for SimpleHeap.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 08 May 2016, 02:37
by HotKeyIt
I have improved exported functions and fixed some bugs when exiting script. Also fixed AhkExported() to work for main script.

Re: [AHK_H v2] Native multi-threading using thread local storage (without AutoHotkey.dll)

Posted: 09 May 2016, 11:02
by newscripter
You are doing god's work. Thank you HotKeyIt!