B Byak@ Active Member Licensed User May 19, 2009 #1 how i'm understand it is not real,arrays only global? i want use strSplit and getcontrols but sub with this operators called by 2 threads.and i have error 'array changed'
how i'm understand it is not real,arrays only global? i want use strSplit and getcontrols but sub with this operators called by 2 threads.and i have error 'array changed'
B Byak@ Active Member Licensed User May 19, 2009 #3 Code: Copy Public Sub objectexist(name,module) Dim gdgtemp(0) gdgtemp()=GetControls("") ex=main.arrayex.IndexOf(gdgtemp(),module&"."&name,0,ArrayLen(gdgtemp())) return ex end sub or Code: Copy sub drawimage(image,params) dim gdgtemp(0) gdgtemp()=strsplit(params,",") x=gdgtemp(0) y=gdgtemp(1) h=gdgtemp(2) w=gdgtemp(3) ... end sub if two threads call this sub at one moment i have error 'array changed'
Code: Copy Public Sub objectexist(name,module) Dim gdgtemp(0) gdgtemp()=GetControls("") ex=main.arrayex.IndexOf(gdgtemp(),module&"."&name,0,ArrayLen(gdgtemp())) return ex end sub or Code: Copy sub drawimage(image,params) dim gdgtemp(0) gdgtemp()=strsplit(params,",") x=gdgtemp(0) y=gdgtemp(1) h=gdgtemp(2) w=gdgtemp(3) ... end sub if two threads call this sub at one moment i have error 'array changed'
agraham Expert Licensed User Longtime User May 19, 2009 #4 This is what the RunLocked methods are for. When two (or more) threads, including the main thread, call the same Sub then the Sub should be invoked via RunLocked to avoid the Sub being entered twice at the same time by different threads. Try something like : Thread1.Runlocked2("ModuleName_objectexist", name,module) Note that all the threads that invoke this method must RunLock it on the same Thread object, not use their own RunLocked method. The Thread on which RunLocked is invoked is acting as the object that is locked preventing other threads accessing the Sub until RunLocked has returned to the first caller. Also note that RunLocked is a normal call and runs on the thread that called it so, as usual, don't touch any GUI elements in a Sub run by RunLocked unless you have invoked RunLocked directly or indirectly from a Thread event or by CallGuiSub in BasicLib.
This is what the RunLocked methods are for. When two (or more) threads, including the main thread, call the same Sub then the Sub should be invoked via RunLocked to avoid the Sub being entered twice at the same time by different threads. Try something like : Thread1.Runlocked2("ModuleName_objectexist", name,module) Note that all the threads that invoke this method must RunLock it on the same Thread object, not use their own RunLocked method. The Thread on which RunLocked is invoked is acting as the object that is locked preventing other threads accessing the Sub until RunLocked has returned to the first caller. Also note that RunLocked is a normal call and runs on the thread that called it so, as usual, don't touch any GUI elements in a Sub run by RunLocked unless you have invoked RunLocked directly or indirectly from a Thread event or by CallGuiSub in BasicLib.
B Byak@ Active Member Licensed User May 19, 2009 #5 big thanks agraham) but if runlocked, i can not sleep thread =((( or can?
agraham Expert Licensed User Longtime User May 19, 2009 #6 Byak@ said: if runlocked, i can not sleep thread =((( or can? Click to expand... I don't know why you should think that. RunLocked is just like a call to a Sub unless another thread is running the same Sub in which case the second thread is suspended until RunLocked returns to the first thread, then the second thread is allowed to run. Sleeping a thread is entirely independent of this process.
Byak@ said: if runlocked, i can not sleep thread =((( or can? Click to expand... I don't know why you should think that. RunLocked is just like a call to a Sub unless another thread is running the same Sub in which case the second thread is suspended until RunLocked returns to the first thread, then the second thread is allowed to run. Sleeping a thread is entirely independent of this process.