13_Review Lecture

Now a common topic the concept of cri4cal regions and

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: alance Task 1 1 2 3 4 0 0 1 1 Task 2 newBalance = balance + 1; newBalance = balance + 1; balance = newBalance; balance = newBalance; ); The effect of this scenario is that Task 1 did nothing, because in Step 4 Task 2 overrides Task 1's result. Obviously, the problem is that Task 1 and Task 2 are accessing a common resource in a way that causes conflict. This is a common problem known as a race condi*on in mul4threaded programs. A class is said to be thread- safe if an object of the class does not cause a race condi4on in the presence of mul4ple threads. As demonstrated in the preceding example, the Account class is not thread- safe. 32 The synchronized keyword Critical Region •  To avoid race conditions, more than one thread must be prevented from simultaneously entering certain part of the progr...
View Full Document

This document was uploaded on 03/11/2014.

Ask a homework question - tutors are online