Computer Science, asked by Ankitpanghal929, 1 year ago

Writing the multiple variables in writere in java

Answers

Answered by Anonymous
4
hii dear!!

here ur answer!!

▪>>We have 2 threads. One is a reader. The other is a writer thread who share these 2 variables:

Object data
boolean ready
Do I need to make both volatile? Is it sufficient to make 'ready' volatile?

write() {
data = <some data>
ready = true;
}

read() {
if (ready) {
consume(data);
ready = false;
}
}
Do I need to make both variables volatile?

Based on my limited understnding of the java memory model, I think I only have to make 'ready' volatile as all the code before reading/writing 'ready' happens-before the code after the reading/writing of 'ready' variable?

Update: For the purposes of this question, assume that atomicity is not an issue. The production and consumption of data is atomic.

♡hope its really help u i create

plz mark brainlist!!
________________
Similar questions