13_Review Lecture

Obviously the problem is that task 1 and task 2 are

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; parallel { // two calls happen in parallel x.set(9223372036854775807); x.set(0); } assert x.i == 0? assert x.i == 9223372036854775807? assert x.i == 9223372034707292159? assert x.i == 2147483647? •  Programmer’s intent – Execute the instruction in a non-divisible way •  In Java, long is a 64 bit binary number occupies two words on 32bit machines •  A write operations is broken down to two instructions 9223372036854775807 = 0x7FFF FFFF 0 = 0x0000 0000 •  Memory sees: Most significant half: 0x7FFF or 0x0000 Less significant half: FFFF or 0000 Thread Synchronization A shared resource may be corrupted if it is accessed simultaneously by multiple threads. For example, two unsynchronized threads accessing the same bank account may cause conflict. Step balance thread[i] 1 2 3 4 0 0 1 1 thread[j] newBalance = bank.getBalance() + 1; newBalance = bank.getBalance() + 1; bank.setBalance(newBalance); bank.setBalance(newBalance); 31 Race Condition What, then, caused the error in the example? Here is a possible scenario: Step b...
View Full Document

Ask a homework question - tutors are online