07.01.2013 Views

David Defour - Université de Perpignan

David Defour - Université de Perpignan

David Defour - Université de Perpignan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Arbitrating Contention for Shared<br />

Resources<br />

• Synchronizing a section of co<strong>de</strong><br />

synchronized(someObject) {<br />

co<strong>de</strong><br />

}<br />

• Fixing the previous race condition<br />

public void run() {<br />

int currentThreadNum;<br />

synchronized(this) {<br />

currentThreadNum = mLatestThreadNum;<br />

System.out.printf("Setting currentNum to %s%n",<br />

currentThreadNum);<br />

mLatestThreadNum = mLatestThreadNum + 1;<br />

}<br />

for (int i = 0; i < LOOP_LIMIT; i++) {<br />

...<br />

}<br />

}<br />

719<br />

jeudi 26 janvier 12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!