To what extent can the VM change order of execution

Hi
I've been reading a book named "Java Threads, Third Edition" from O'Reilly Media by Scott Oaks and Henry Wong. The book has a subchapter named "The Effect of Reordering Statements" where it states that the vm is free to change the order of executement, and that the order of operations can therefore not be used to ensure that a class/code is threadsafe. Ill just point a snip from the book to illustrate. The example code:
public int currentScore, totalScore, finalScore
public void resetScore(boolean done) {
    totalScore += currentScore;
    if (done) {
        finalScore = totalScore;
        currentScore = 0;
public int getFinalScore( ) {
    if (currentScore == 0{)
        return finalScore;
    return -1;
}It then suggest that these two runs can take place. Run 1:
- Thread1: Update total score
- Thread2: See if currentScore == 0
- Thread2: Return -1
- Thread1: Update finalScore
- Thread1: Set currentScore == 0
Run 2:
- Thread1: Update total score
- Thread1: Set currentScore == 0
- Thread2: See if currentScore == 0
- Thread2: Return finalScore
- Thread1: Update finalScore
My question now is if this info is correct, and if so, to what extent can the vm rearange the order of executement? Say I have this code (simplified example):
class SelectorThread implements Runnable{
private volatile boolean keepRunning;
public void run(){
   while(keepRunning){
       //Dosomething
        internalSelector.select();
public void stopIt(){
    keepRunning = false;
     internalSelector.wakeup();
}Would it then be possible for the vm to rearrange the code in stopIt(), thus making it possible to get a : "T1: wake up selector, T2: selector checks keepRunning, T2: selector goes back to sleep, T1: keepRunning is changed to false" scenario? Or is the above code "safe" to use?

Thanks for the answer :)
Am I then right in concluding that the stopIT() method I described is then not guarantueed to deliver the wanted result? (that the select thread exits the loop). If the vm-orders the statements as you show and the thread timing is a bit unlucky you could end up with:
Thread A (the one calling stopIT()) executes internalSelector.wakeup();
Thread B (the thread in the loop) wakes up
Thread B checks the while condition which still evalutes true and ends back with blocking on .select()
Thread A changes the value of keepRunning to false
Thereby possibly leaving threadB blocked "forever" if no other events occur.
Is this intepretation of the mechanicm correct? meaning do I need to change the implementation of the stopIt() method to assure it will produce the wanted result?

Similar Messages

  • To what extent can customer's access usage records?

    We all know that Verizon maintains extensive records on the usage of phones. To what extent can the actual customer access the information Verizon stores about the usage of his device?

    If you're the Account Owner of a post-paid account and logged in as such, you have access to your current billing cycle call/data/text logs via your on-line My Verizon account under View My Usage  You also have access to the past 18 months' worth of call logs, as well as the past 90 days' worth of data/text logs, by viewing the past bills in your My Verizon account under View Bill.

  • Find my iphone: how can the thief change the phone name?

    Hello.
    I have had 3 iphones stolen the last 5 months.
    Finally I got a ping from one of the stolen iPhones. I could follow it for almost 2 months. Since I am in a country were the police wont do anything it does not help me that I have name/address of the thief.
    But this strange thing happened last day/last ping I got from my stolen iPhone:
    Somehow the device is removed from my "find my iphone" list and/or the device have changed name.
    The device was locked with passcode/touch ID.
    I have changed password AppleID 3 times since the phone was stolen (well: The police wanted my password/AppleID to track the phone. Somehow the thief got this information and I found out when my address book had 150 new entries from the thief).
    I managed to change password and lock the phone remotely after that incident.
    To bad I cant ask Apple any question.
    How can a device be removed from my account? (I have not got any warnings that someone have logged into my iCloud account from a new device/location)
    How can a thief change the name of a stolen iPhone that is locked with touchID/Password/passcode? (Iphone6).  Is there still DFI attacks that can wipe the phones?
    How can I check if my account is hacked?
    Why cant I remotely detonate my iPhone? The battery would be a nice little bomb making the phone worthless?
    (and F lazy Russian tourists police that just ask "what should we do" when I provide address/name/video of a person that have stolen stuff worth over 5000 dollars including iphones/Ipads)

    Hi Brirendine,
    Take a look at the instructions below for what to do when you sell your iPhone.  If you have followed all of these steps, the new owner should contact his/her carrier to activate the phone.
    iCloud: Activation Lock
    http://support.apple.com/kb/PH13695
    With iOS 7 or later, Find My iPhone includes a feature called Activation Lock, which is turned on automatically when you set up Find My iPhone. Activation Lock makes it harder for anyone to use or sell your iPhone, iPad, or iPod touch if it’s ever lost or stolen. 
    With Activation Lock, your Apple ID and password are required before anyone can:
    Turn off Find My iPhone on your device
    Sign out of iCloud on your device
    Erase and reactivate your device
    Important:    Make sure to remember your Apple ID and password, and that your password is unique and secure—someone else shouldn’t be able to guess it. For more information, see the Apple Support article Security and your Apple ID. 
    If you want to give away or sell your device, be sure to erase your content and settings (in Settings > General > Reset > Erase All Content and Settings). When you erase your content, Find My iPhone and Activation Lock are also turned off. 
    If you no longer have the device, follow the instructions to remove a device you no longer have. For more information, see the Apple Support article What to do before selling or giving away your iPhone, iPad, or iPod touch. 
    If you’re purchasing or selling a used device, you can check its Activation Lock status at icloud.com/activationlock from a Mac or PC. 
    For more information about Activation Lock, see the Apple Support article Find My iPhone Activation Lock. 
    Last Modified: Jan 8, 2015
    I hope this information helps ....
    - Judy

  • Can the specific changes/updates made to a customer be captured with the detail of changes?

    One of our 11i Customer placed the below requirement:
    We are creating a report that will extract customers that have changed or updated in Oracle. The user requested to include also the specific change made to the customer. Is there a way that we can capture what are the changes/updates made to a customer?
    We understand that the last update date and updated by could be tracked. But, is it possible to find what change was done in which field?
    Gurus, kindly respond.

    This will only tell you if the user you're interested in was the most recent person to update that table, but not what they did, and if they were not the most recent, then all trace will be gone.
    Have you considered enabling auditing? It's not going to provide details of anything which has already happened, but it keeps fairly detailed records, but at the cost of a large performance hit.

  • Can the default column order in the response tab be set during form design?

    I know the response columns can be rearranged in the report but can the order be "pre-ordained" as part of form design?

    Hi,
    Sorry I am not aware of your form NOT created in FormsCentral.
    FormsCentral doesn't support to rearrange the column order in Form Design tab, if it is an imported PDF form. The column order in PDF form depends on the order of the field in the PDF structure.  You can post a feature request from http://forums.adobe.com/community/formscentral?view=idea
    Thanks,
    Ying

  • I have lost my iphone 5 and reported it to police can the thief change it's imei and escape from tracking

    can imei be changed of iphone5

    No. The IMEI is burnt onto the main board and cannot be changed without destroying or seriously damaging the unit.
    Call the carrier too and have them block the IMEI on the national registry so the miscreant can't switch to another carrier.

  • What else can the x-fi do?

    Hi guys just bought a flute and was thinking about doing some recording. anyway i got a x-fi fatality with the drive bay and everything so i have every connection under the sun but i need some reading to do as to what exactly i can do with this soundcard. i got it for games and movies mostly but now would like to do some recording with it so would like some info on what i can do and where to start really.
    Cheers.
    Ellimist

    I think with your card, you be able to do everything what you can do w/ any other card + you can have some hardware features not common for std sound cards. What you need for recording the flute is a good pre-amplified microphone. If needed, all background music (drums/piano/bass/guitar/strings/synths/etc./etc.) can be done through MIDI + VSTi/DXi/soundfonts or by using samples/loops.
    For recording you are after, just download some ASIO/VST capable recording software and read the user's guide bundled w/ it.
    Cockos Reaper + VST/DX plug-ins listed @ KVR would be a good starting setup.
    W/ some older card models Creative included a guide named as "Music Creation Guide". You could find all necessary information for recording and certain software normally used for recording.
    - http://www.cockos.com/reaper/
    - http://www.kvraudio.com/get.php
    - google for soundfont downloads (there are plenty of sites offering free soundfonts)
    jutapa
    Message Edited by jutapa on 06-21-2008 11:27 AM

  • What will be the significance change I will experience with 2GB memory!

    Currently, I am using a SONY VAIO with 256 MB memory. I honestly felt that things ran pretty smoothly. I've had many applications open at the sametime. However, I do recall working with video usually was a pain. So IMAC with 2GB is like 8 times the memory I have with my SONY right? Can anyone explain to me the significant change I will experience with 2GB of memory versus 256MB? I'm expecting for things to run even faster/smoother (if that's possible). As mentioned, I've been content with my Sony. But it's so outdated, that I needed something new.

    the 256mb video card makes a huge differance for me using Maya and Photoshop. Rendering and filter effects are dramaticly faster. Maybe later i'll go with 3gigs of ram, but for now the gigs is working great.
    if you're coming from 256mb of ram I think you will be hard pressed to find a single thing that isnt many times faster on a core 2 duo with 2 gigs of ram.
    for example: on my prior G5 imac 1.8 ghz w/ 2gigs of ram it would take almost 3 hours to encode a full dvd to mpeg4 format. on my core 2 duo with 2 gigs of ram it took 35mins.
    hope this helps!

  • How can we ask an order of execution ?

    I want to command un order of execution of two operations in my VI. At the beginning, my program worked well but when I added a for loop, the program doesn't work enought like I want it work...
    Thanks in advance
    hasna

    I've just succeeded in solving my probem but I have another, I want to open a query of my database thanks to labview but I want to open it and it must stay open but noaw, it open and disapear immeditly...
    Have you an idea for my problem ???
    Attachments:
    lecture_de_la_table.vi ‏24 KB

  • What else can you manually change in the Manifest XML?

    I am developing native Java apps as well as Adobe AIR for Android apps.
    I know you can manually change the AndroidManifest.xml file (even if you're using the Flash CS5 Adobe AIR for Android plug-in) to do some different things.
    What have you guys had success doing?  I've only figured out how to enable moving the apps to the SD card (location "auto").
    Anyone else?
    -Adele
    AdmobAndroid.com

    Laxidasical,
    Make sure you set the location to auto manually within the XML file, then don't touch the publish settings within the .FLA
    file.  Next time you publish, you should be able to manually move it to SD card.  I can show you the settings if you want it to default to SD card as well.
    If it's not working for you, please let me know your process and maybe I can troubleshoot it.
    Everyone else,
    Do you know of other things to manually change in the manifest xml file?
    I also develop native apps in Eclipse and there's tons more I can do there, but so far, I haven't been able to get any of those changes to work in Adobe AIR for Android.
    -Adele
    http://admobandroid.com

  • What's with the pricing changes in tv shows?

    I thought that the prices of "certian" tv shows was supposed to be going down, but I'm seeing them go up. Example 1: Had in my wish list to start buying CSI:Crime Scene Investigation. Price at the time of adding to wish list, $14.99. Now noticing the price to buy is $35.99 for the season. Example 2: Star trek Enterprise, season 4. Wish list price was $12.99 for season, now only available per episode purchase and listing 20 episodes with 2 missing totaling $39.80 for an incomplete season. What is going on here with these price increases? It is now cheaper for me to just go buy the seasons on standard dvd. I've tried googling to see if there is any news as to why this is happening, with no info. I had planned on buying many a season of tv shows, and I know Apple seemed to be trying to push for increased sales in the tv show section (which I was more than willing to help with) but with these costs I can't justify it. Does anyone know why Apple is doing this? Thanks in advance.

    Many shows are available in both SD and HD versions. The HD versions are more expensive. Perhaps you're looking at those?

  • What's with the color changing dot on the white background google?

    When I am in the google app a white screen with a dot that changes colors appears and I can't get rid of it.  Any suggestions?  

    That is google's way of telling you the app is processing or loading data.
    You can get rid of it by deleting the app.

  • Up to what tension can the Codec C40 be used?

    I am using a tanberg Cisco Codec C40 and I need to
    do some tests on it which requires to put the codec under a tension of 140 VAC for 60 Hz. In the datasheet it is said :
    "100–240 VAC, 50/60 Hz "
    does that mean that it would still be safe if I put a tension of 140 VAC, 60 Hz or do I also have to change the frequency?
    Thank you for your help,
    Joanie

    As long voltage and frequency, even indipendently, are within the published specifications, (there can be an additional tolerance), that will work ok.

  • To what extent can I replicate a Nokia 700?

    ... using Nokia PC Suite?
    I have a 700 and need to have an identically configured spare phone.
    What is the best way to achieve that?
    Presumably all Nokia shop apps will need to be re-downloaded.

    As usual, nobody replied here despite Nokia reps reading these messages and removing ones they don't like...
    Anyway, in case anybody is interested, this is what I did:
    1) Bought the 2nd phone
    2) Made sure it had the latest firmware (same as the 1st one)
    3) Put in a microSD card into the 2nd one, same as the 1st one has (drive F
    4) Using Nokia Suite, I did a backup of the whole of the 1st one and restored it into the 2nd one
    5) I re-installed the few apps I bought. This involves moving the old SIM temporarily into the 2nd phone, because Nokia changed their shop to not allow downloads anymore; instead they send you a SMS with the download URL. There is supposed to be a way to re-download paid-for apps if you move the SIM as described, without paying for them again, which would be only fair, but it didn't seem to work and I bought a couple of little ones again (life is too short). For a few apps I had the .sis file which makes it trivial, of course, but that is rare nowadays.
    Most of the config did restore correctly, including apparently config of **Nokia** apps (which was expected), but also suprisingly the config of most of the non-Nokia apps which were installed *after* the restore also came up as before. I guess the restore must have restored some workspace areas in which these apps were storing their config, so that when they were installed they picked up their old config.
    Curiously the "home screen" configs (wallpaper settings) did not get restored, but they are just trivia.
    I did not retest whether Nokia suite has recently fixed the well known bug in that custom labels in the contacts book (e.g. renaming somebody's "Mobile" number label to "Vodafone") did not get backed up / restored.
    Nokia offer support over email, which appears good, but in reality it is done by people with little knowledge of phones and very poor English, who seem to be dropping in standard phrases from a script and do not understand questions asked even if they are presented several times, carefully re-worded. They also have no apparent access to better support. For example they claim that deleting an email also deletes it from the (POP) server; I have just proved yet again this is false (unless it is highly context sensitive). I am after deleting emails from the server - like every previous Nokia phone I had was capable of.

  • To what extent can XIR2 users use XIR3 platform, if at all?

    We are deploying XIR3 and we have suddenly been asked if XIR2 users can use the system. Is so what can / cannot be used? For example:
    1. Can an XIR2 user login to an XIR2 repository?
    2. Can they use an XIR2 Desktop Intelligence against an XIR3 CMS, Universe?
    3. Can they schedule an XIR2 report via an XIR3 repository?
    My suspicions are that they cannot, but if someone would be so kind as to clarify or advise which document to refer to that would be great
    Thanks...

    It's a large multinational company. One team is Global projects (just migrated from v 5.1.6 to XIR3). The other team is on a seperate group (R2, and will not upgrade for a while).
    One team has an XIR3 server, R3 universes and R3 reports. The other team only has an R2 deployment (reports, universes, connections - all). The R2 deployment has a different set of users, reports and universes but they need some of the R3 reports, connections and universes even though their users do not exist in the R3 environment.
    I found the following on page 57 of xi3_bip_upgrade_en.pdf:
    Although it is recommended that you upgrade all your Desktop Intelligence
    clients to Desktop Intelligence XI 3.0, you can continue using Desktop
    Intelligence XI Release 2 clients against a BusinessObjects Enterprise XI
    3.0 server during the upgrade phase.
    You can continue to use Desktop Intelligence XI Release 2 clients to connect
    to an XI 3.0Central Management Server (CMS), and to create, view, and
    edit Desktop Intelligence XI 3.0 documents that use either of the following.
    u2022 XI Release 2 universes.
    u2022 XI 3.0 universes that are based on XI Release 2 universe connections.
    You can also use Desktop Intelligence XI Release 2 and XI 3.0 clients on
    the same computer.
    Desktop Intelligence XI Release 2 does not work with universes that are
    based on XI 3.0 universe connections.
    Desktop Intelligence XI 3.0 clients work with both XI Release 2 and XI 3.0
    universes and universe connections. However, you cannot use Desktop
    Intelligence XI 3.0 to connect to an XI Release 2 CMS, or to use Desktop
    Intelligence documents through an XI Release 2InfoView.
    Note:
    u2022 It is highly recommended that you upgrade to Desktop Intelligence XI 3.0
    clients. Desktop Intelligence Release 2 and BusinessObjects Enterprise
    XI 3.0 interconnectivity should only be used to make the upgrade
    BusinessObjects Enterprise 3.0 easier.
    u2022 Do not use the Central Management Console (CMC) or Designer XI 3.0
    to edit XI Release 2 universe connections. Using the CMC or Designer
    to edit an XI Release 2 universe connection will convert the universe
    connection to an XI 3.0 format, and break compatibility. Desktop
    Intelligence XI Release 2 clients will not be able to use the XI 3.0 universe
    connections.

Maybe you are looking for

  • Sumary report chart colours

    is there a way to change the chart colours in the summary report. The default colours that are assigned to the selection, are not very intuitive. If you had a question that gave a range of five possible answers ranging from poor to excellent, the col

  • Xserve Raid - use it as standalone storage?

    hi there! i have a small network with some pcs (3 running winxp, 1 win2000), 2 os9 macs and 2 g5s. i need big data storage in the size of 7-10TB. can i use the Xserve Raid as standalone storage in the network, or does it need the xserve as server? do

  • Buffered Reader from  a JTextArea?

    Hi everyone, can anyone please tell me how i can get a buffered reader from a JTextArea? This is what I would like to do where the following gets displayed in the JTextArea Please enter your name: (user enters data here) Please enter your id number:

  • Issue: CO15 Order confirmation

    Hi, In case of u2018Production Orderu2019 confirmation I am facing following issue: For the u2018Production Orderu2019 confirmation we use transaction CO15. While confirming the u2018Production orderu2019 system is giving error u2018Posting period 00

  • Table Spaces Export

    Hi, I want to export the some table spaces to the new server ( on the new server I will create the new database and i want to import these exported tabale spaces) I want export the Table spaces, their tables, user and grants. These are arrount 100 ta