All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: About Question enthuware.ocpjp.v8.2.1558 :
PostPosted: Thu May 26, 2016 7:51 pm 
Offline

Joined: Sat Apr 30, 2016 4:10 am
Posts: 1
Hello!

The variable "threadcounter" is static, then your value is only one. The final instruction of explanations is wrong:
"It is, therefore, possible that each of the ten threads see its value as 0 and updated it to 1. Thus, one possible outcome could be that 1 is printed 10 times!"
When of all threads executes the method run, even if the same time, the variable "threadcounter" will be increased. Right or not?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1558 :
PostPosted: Thu May 26, 2016 10:39 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6757
No, the explanation is correct. As explained in the explanation, threadcounter is not volatile and none of the threads are accessing the variable in a synchronized block, so one thread may change its value from 0 to 1 but another thread may still see 0.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1558 :
PostPosted: Sat Aug 12, 2017 3:12 pm 
Offline

Joined: Sat Aug 12, 2017 1:43 pm
Posts: 6
Futhermore, even if threadcounter was volatile it doesn't help to see all 10 numbers
The reason is:
increment is not atomic operation, so two or more threads can read the same (even volatile) variable and rewrite end value


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1558 :
PostPosted: Sun Aug 13, 2017 2:13 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6757
That is correct. This has been added to the explanation.

thank you for your feedback!
Paul.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum