does it exist? I mean, if two threads try to acces at the same variable, what happens? I mean.. you have a lot of threads in a game.. a silent colission in the background, that can happen if various threads use the same var.. so .. do you have to built your own monitors? Lock them up?
Would something like this
function threadSafety(globalBoolNr,value2ChangeInto,boolLockedNR)
.....while(true).do
..........ifboolLocks[boolLockedNR]==true.then
..........Sleep(5)
..........else
..........boolLocks[boolLockedNR]=true
..........globalBooleans[globalBoolNr]=value2ChangeInto
..........boolLocks[boolLockedNR]=false
..........return
..........end
.....end
end
be sufficient?
Lua thread safety..
Moderator: Moderators
Re: Lua thread safety..
there are no threads only coroutines
-> no reason to worry about threading
-> no reason to worry about threading
Re: Lua thread safety..
So its basically a timeshared simulation of threads, cutting off at random? Same thing windows uses to schedule processes with a one Core?
Its just, it would be so nice if this would solve.. i mean. the thread just vannishes. A freaking OS-Loop.
while(true) do
Spring.Echo(Alive)
end
Ends.. No Error Message. Nothing. Just Silence. And the other threads going mad because the sensory data provided by the loop is amiss.
Its just, it would be so nice if this would solve.. i mean. the thread just vannishes. A freaking OS-Loop.
while(true) do
Spring.Echo(Alive)
end
Ends.. No Error Message. Nothing. Just Silence. And the other threads going mad because the sensory data provided by the loop is amiss.
Last edited by PicassoCT on 12 Mar 2012, 02:00, edited 1 time in total.
Re: Lua thread safety..
not really random, it cuts off at `yield()`which is automatically called by sleep()
so never ever make a loop w/o a sleep in its body.
so never ever make a loop w/o a sleep in its body.
Re: Lua thread safety..
will check all the whiles for missing Sleep(S)
still this is .. strange, so even when there is the feared "harddrive-wait for instructions after cache and memory-miss" it will not pause the thread and idle until the data arrives to make it to the next sleep? Sounds inefficient.. but well, im not an expert.
still this is .. strange, so even when there is the feared "harddrive-wait for instructions after cache and memory-miss" it will not pause the thread and idle until the data arrives to make it to the next sleep? Sounds inefficient.. but well, im not an expert.
Re: Lua thread safety..
while(weareatit) do
Spring.Echo("Wasntit")
end
All the whiles get there rest..
Could a Signal fired off end a thread that doesent have a SetSignalMask?
I mean, what happens if i Signal(256) and there is no corresponding signal Mask?
Spring.Echo("Wasntit")
end
All the whiles get there rest..
Could a Signal fired off end a thread that doesent have a SetSignalMask?
I mean, what happens if i Signal(256) and there is no corresponding signal Mask?
Re: Lua thread safety..
PicassoCT wrote:Could a Signal fired off end a thread that doesent have a SetSignalMask?

"SetSignalMask assigns a mask to the currently running thread (any new threads started by this one will inherit the signal mask)"
http://springrts.com/wiki/Animation-LuaCallouts#Threads
Re: Lua thread safety..
thx.. overread that. Happens way to often. So can a new Signal Mask break that heritage?
Re: Lua thread safety..
Yes.
SetSignalMask(name) = give the current thread a name
Signal(name) = kill all threads with the given name
So when you call SetSignalMask with a different name than the name inherited from the "parent" thread, the heritage is broken.
If name is a number there is a special case that all threads with a name for which the bitwise-and with the signal is non-zero are killed. So after SetSignalMask(3), both Signal(1) and Signal(2) will kill this thread. Similarly, Signal(3) will kill all threads with a numeric signal mask with either one or both of the least significant bits set.
You can exploit the fact that every new empty table is a unique object to create unique symbolic thread names:
SetSignalMask(name) = give the current thread a name
Signal(name) = kill all threads with the given name
So when you call SetSignalMask with a different name than the name inherited from the "parent" thread, the heritage is broken.
If name is a number there is a special case that all threads with a name for which the bitwise-and with the signal is non-zero are killed. So after SetSignalMask(3), both Signal(1) and Signal(2) will kill this thread. Similarly, Signal(3) will kill all threads with a numeric signal mask with either one or both of the least significant bits set.
You can exploit the fact that every new empty table is a unique object to create unique symbolic thread names:
Code: Select all
local MY_UNIQUE_NAME = {}
...
Signal(MY_UNIQUE_NAME)
SetSignalMask(MY_UNIQUE_NAME)
Re: Lua thread safety..
Thanks Tobi.