Originally posted by Tim Holmes:
My question is in the below code, does each thread have it's own copy of someVariable? So if Thread "A" modifies "someVariable" and then thread "B" does also, then it doesn't really matter because they have their own copy right? ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Tim Holmes:
This may seem like a dumb question, but i am trying to understand threading better. If that is the case that "someVariable" is unique to each thread and also that methods are unique to each thread, then what is the point in synchronizing?
The whole point of synchronizing is so that a variable or method does not get accessed by more than one thread at any point in time, right?
So the only time that would happen would be when a method or variable is "static" at which point there would be only one copy to work with and you would need to restrict it to one thread at a time. Right??[/qb]
Originally posted by Tim Holmes:
...you pass only one instance of a "runnable" object into the thread. Is it possible to do that with a object that extends the Thread class? ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Tim Holmes:
...My question is on example B what is the point in synchronizing if the variable "gear" is not shared? Both threads are gauranteed to access the "gear" variable independently! In addition, can a run method on a class that extends thread ever be called by more than one thread? ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Well THAT's new! Comfort me, reliable tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|