All Day I have tried to accomplish the following using threads, and just
could not get it to work. I want them to thrash back and forth having
the power to do stuff…
I want two threads to execute and fight each other to send commands to a
unit. With each thread they just call methods with certain arguments.
I want them to send the commands at the same time.
I guess I am realizing that isn’t possible, only one will have control
at a time, thats fine, I want them to pass control to each other
continously, seemingly randomly to me from the outside.
Also in both threads i have a forever loop.
so for example
a = Thread.new do
method that sends commands, about 60 of them
b = Thread.new do
method that sends different commands, about 20 of them
no matter what, thread a only runs a few commands before thead b takes
over forever, and thread a never executes again.
To combat the problem I tried doing this after the creation of the
threads, in main I guess you call it…
a.priority = -1
b.priority = -2
b.priority = -1
a.priority = -2
I also tried positioning Thread.pass randomly throughout the two
threads, hoping that would tell the thread, hey let the other guy have a
chance, then that thread would get to his Thread.pass meaning let the
first guy have a chance to send some stuff!!
All these ways have some outcome, just the second thread executes
Any ideas, thank you very much for the help!!