local array...

Byak@

Active Member
Licensed User
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'
 

Byak@

Active Member
Licensed User
B4X:
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
B4X:
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
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.
 

Byak@

Active Member
Licensed User
big thanks agraham)
but if runlocked, i can not sleep thread =((( or can?
 

agraham

Expert
Licensed User
Longtime User
if runlocked, i can not sleep thread =((( or can?
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.
 
Top