Multithreading (in Java) -
i trying understand multithreading , confused how timing of execution of multiple threads causes problems race conditions. read in article: "when introduce concept of multithreading, opening possibility of 2 threads accessing/modifying same object in memory @ same time." mean "at same time"? mean memory location can read multiple threads @ same instance of time example, 2 threads read value of variable @ 1.1 second mark? if yes, diagram java concurrency in practice imply thread b read value 9 tad later thread a? how should interpret it?
i try clear , short possible.
let's have variable stored in part of memory adress 0x101010. let's variable counter counts how many times function (x) called. there 2 threads (a , b) call function x. has called x , 0.0001 ms later b did well. let's initial value of counter 0. has read value 0 @ time 0s , incremented @ time 0.0002 ms. @ time 0.0002 ms value 1. however, b has read value @ time 0.0001ms (0.0001 < 0.0002). @ time counter still zero. , incremented 1 @ time 0.0003 ms. in end, counter value 1, when should 2.
Comments
Post a Comment