multithreading of scripts of several objects . multithreaded data processing
Posted: 29 Dec 2021, 18:03
Hello. I have some drones from rotots\mobile\Quadcopter.ttm. They are loaded as models.
They have the same code of scripts that describe the movement.
I have n tasks to which drones are flying.
Drone 1 takes task 1, drone 2 takes task 2, drone k takes task k , and so on while drones or tasks are free.
If, for example, drone 1 has reached and completed its task, it takes the next free task from the list.
I organized this process like this:
During the flight, each drone "monitors" the same data array (PointArray)-an array of references to points, which lies in the "StringSignal". And if the drone decides to fly to the next point, it changes the value of the i element of the array to -1. Thus , the next copter simply does not see this point and takes the next value != -1.
But before I write -1 to the desired position in the array, I need to get the latest-up-to-date copy of this array. I read it using readPOINTArray, set -1 and write it again using writePOINTArray.
Naturally, to avoid problems with multithreading, I use the block
Inside which I call readPOINTArray and writePOINTArray.
My question is: did I organize this process correctly?
And I still haven't figured out how the
block works
Does it suspend the multithreaded execution of only this script in which it is written , or the entire program and scripts at that moment while we are in it ??
I really hope for your answer!!. Thank you for your patience and help!
They have the same code of scripts that describe the movement.
I have n tasks to which drones are flying.
Drone 1 takes task 1, drone 2 takes task 2, drone k takes task k , and so on while drones or tasks are free.
If, for example, drone 1 has reached and completed its task, it takes the next free task from the list.
I organized this process like this:
Code: Select all
function writePOINTArray()
sim.setStringSignal('POINTArray',sim.packTable(POINTArray))
end
function readPOINTArray()
local data=sim.getStringSignal('POINTArray')
if data then
data=sim.unpackTable(data)
else
data={}
end
return data
end
During the flight, each drone "monitors" the same data array (PointArray)-an array of references to points, which lies in the "StringSignal". And if the drone decides to fly to the next point, it changes the value of the i element of the array to -1. Thus , the next copter simply does not see this point and takes the next value != -1.
But before I write -1 to the desired position in the array, I need to get the latest-up-to-date copy of this array. I read it using readPOINTArray, set -1 and write it again using writePOINTArray.
Naturally, to avoid problems with multithreading, I use the block
Code: Select all
sim.setThreadAutomaticSwitch(false)
....
sim.setThreadAutomaticSwitch(true)
My question is: did I organize this process correctly?
And I still haven't figured out how the
Code: Select all
sim.setThreadAutomaticSwitch(false)
....
sim.setThreadAutomaticSwitch(true)
Does it suspend the multithreaded execution of only this script in which it is written , or the entire program and scripts at that moment while we are in it ??
I really hope for your answer!!. Thank you for your patience and help!