Page 1 of 1
Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 04 Jun 2017, 03:27
by lamarcgasolridge
I am trying to add another thread to my script.
Code: Select all
script script script script script
script script script script script
script script script script script
AhkThread("
(
Alias(variable1," getvar(variable1) "), Alias(variable2," getvar(variable2) ")
#include function.ahk
function()
exitapp
return
)")
script script script script script
script script script script script
script script script script script
However I keep getting this popup:
Not sure what the deal is. Happens about 20% of the time.
Also, is there any way to pass a variable from the main script to the ahkthread script?
Re: Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 04 Jun 2017, 05:20
by HotKeyIt
This is most likely because you are accessing/changing the variable from multiple threads, I would encourage you to use
CriticalObjectCode: Select all
obj := CriticalObject() ; Create new critical object
Loop, 4 ; Create 4 Threads.
AhkThread%A_Index% := AhkThread("obj:=CriticalObject(" (&obj) ")`nLoop`nobj[" A_Index "]:= A_Index")
Loop ; Show current content of object.
ToolTip, % obj.1 "`n" obj.2 "`n" obj.3 "`n" obj.4
Esc::ExitApp
Otherwise you will need to use
CriticalSection to make sure that only one thread has access to the variable.
Re: Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 04 Jun 2017, 13:05
by lamarcgasolridge
I have been trying, but it feels like I am nowhere close to making it work
I am mostly confused at where to put the function and also the variables. I've tried to make it work from this
reply you made before to me:
Code: Select all
obj:=CriticalObject()
AhkThread("
(
obj:=CriticalObject(" (&obj) ")
F2::
send, {F1}
msgbox `% obj.variable
Return
)")
F1::
obj.variable:="rainbows" A_Now
return
Esc::ExitApp
All my tries were various forms of the following. Reading the criticalobject/section help pages are outside my league so all I can do is switch things around and pray.
script
variable:=CriticalObject()
AhkThread("
(
variable:=CriticalObject(" (&variable) ")
function()
return
)")
script
msgbox, %variable%
script
- or -
script
obj:=CriticalObject()
AhkThread("
(
obj:=CriticalObject(" (&obj) ")
Alias(variable," getvar(variable) ")
function()
return
)")
script
msgbox, %variable%
script
Re: Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 04 Jun 2017, 13:45
by HotKeyIt
I suggest to stick with CriticalObject and don't use variable and Alias.
Can you show a complete example that is not working for you?
Re: Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 05 Jun 2017, 04:35
by arcticir
This is an example of what I wrote to H version novice:
Code: Select all
f:=ahkFast("#Persistent`na:=[1,2,3]`ntest(s){`nreturn s`n}")
Sleep, 200
f.set("test","2")
MsgBox % f.a.1 " " f.test " " f.test([1,2,"c"]).3
ahkFast(this:="",code:="",wait:=""){
static dll
if isobject(this)
{
s:="__default_Created(){`nstatic _:=__default_Created(),Thread`n"
. "Thread:=CriticalObject(" (&this) "),Thread.base:={__Call:CriticalObject(Func(`"__default_call`")),__set:CriticalObject(Func(`"__default_set`")),__get:CriticalObject(Func(`"__default_get`"))}`n"
. "}`n__default_get(f,n,p:=`"`"){`nglobal`nTry`nreturn (p?`%n`%[p]:`%n`%)`n}`n"
. "__default_set(f,n,p){`nglobal`nTry`nreturn (`%n`%:=p)`n}`n"
. "__default_call(f,n,p*){`n`nif n:=func(n)`nreturn p.Length()?n.call(p*):n.call()`n}`n" code
n:=this.new,n[s]
}
else
{
if !dll
UnZipRawMemory(LockResource(LoadResource(0,ad:=FindResource(0,"F903E44B8A904483A1732BA84EA6191F",10))),SizeofResource(0,ad),dll)
f:=CriticalObject(),f[""]:=r:=MemoryLoadLibrary(&dll),f.fast:=func("ahkFast")
for i,n in {"fn":["ahkFunction","s==sssssssssss"],"fp":["ahkPostFunction","i==sssssssssss"],"new":["ahktextdll","ut==sss"]
,"add":["addScript","ut==si"],"exec":["ahkExec","ut==sui"],"get":["ahkgetvar","s==sui"],"set":["ahkassign","ui==ss"],"sub":["ahkLabel","ui==sui"]
,"pause":["ahkPause","i==s"],"end":["ahkTerminate","i==i"],"Ready":["ahkReady",""],"Reload":["ahkReload","i==i"]}
f[i]:=DynaCall(MemoryGetProcAddress(r,n.1),n.2)
if this!=""
ahkFast(f,this,code)
return f
}
}
Re: Using multiple threads, getting "CONTINUABLE EXCEPTION ACCESS VIOLATION"
Posted: 28 Oct 2020, 10:59
by Galaxis
Greetings!
I hope this helps.
lamarcgasolridge wrote: ↑04 Jun 2017, 03:27
Also, is there any way to pass a variable from the main script to the ahkthread script?
Code: Select all
;pass Variable From MAIN SCRIPT to THREAD
obj:=CriticalObject()
obj.1:="Fire"
obj.2:="Wind"
obj.3:="Ice"
AhkThread("
(
obj:=CriticalObject(" (&obj) ")
msgbox % obj.1 "" "" obj.2 "" "" obj.3
)")
;-----------------------------REVERSED------------------------------------------/
; Pass Variable From THREAD to MAINSCRIPT
Count:=CriticalObject()
AhkThread("
(
object:=CriticalObject(" (&Count) ")
object.1:=""One""
object.2:=""Two""
object.3:=""Three""
)")
msgbox % Count.1 " " Count.2 " " "" Count.3
F1::exitapp
return