Thread question: change competitor Exception

I have a table and two threads are using it, or at least using the reference variable. We ("Reader") just reads the values of him very frequently. The other ("Reassigner") much less frequently reassign reference variable in the array to a new version of the table.

What happens if a collision occurs? I think that nothing bad. Am I wrong? I don't know how model a collision and know empirical, but I don't want to deploy and found out the hard way.

Consider: Reader starts to read the table, lifting the single value, that he needs. At the same time, Reassigner points the reference variable in the array to another array object. Bad? I think that the drive can read just the anonymous orphan table now and soon-to-be with no problems. Or some kind of concurrent modification exception will be thrown. Or is there a bad collision if two threads try to obtain and to reset the address of the array at the same time?

Thanks for any idea.

Jim Ryan says:

Thus, the reader sees is not the new value for who knows how long, if ever, is not catastrophic?

Yes. If I can't avoid this possibility otherwise, I'll have to synchronize.

Another option that may work for you is to declare this volatile reference variable. If your only problem here is that the reader must see each write, for example, that you don't have to worry about atomicity of the actions of several steps that go with writing or reading, then declare this variable of volatile reference will ensure that each reading and writing goes against the master copy. It should be no more overload as well as in the clock (since synchronization is forced against the master copy read/write), and I expect that there is a little less (since the synchronization must obtain and release the lock, while the birds only means that we use the master copy).

However, if your drive is iterate through the table using the shared reference variable and the writer wrote in the reference in the middle of this variable, then the drive will suddenly be reading a different table and could end up with ArrayIndexOutOfBounderException, or at the very least, data for the last part of the table that has no relation to the old part. It is a form of atomicity, that I mentioned, and it can also happen with synchronization if you don't do it right.

A way around this would be for the reader to do something like this:

void someMethod() {
  int[] localReference = sharedReference;

  for (int x : localReference) {
    do stuff
  }
}

In this way, even if the writer becomes the shared reference while the player is an iteration, the iterator won't see it during its current iteration. His localReference will see either the old value or a new, and this value will persist during the entire iteration.

Tags: Java

Similar Questions

  • While playing axis & allies game I get this error message "thread PRINCIPAL caught unhandled exception: Access Violation (C0000005) trapped in 1 B: B3FF94".

    I have an old axis & game cd-rom of the allies that gives me a fit. I get an error message and instructions on what to do, but there is no what to do. So, here is what the error looks like with bells and whistles of boxes/windows.

    Fatal error of initialization:

    thread HAND caught unhandled exception: Access Violation (C0000005) trapped in 1 B: B3FF94

    Then, he wants me to send log files that do not exist to "Atari." Heres so I know... This error is an access violation, which means that a certain part of the space no longer exists on my computor. Is there any help?

    Running win 7. must use compatibility to run cd rom.

    It allows to run fine with no probs.

    Thanks in advance for any advice.

    Original title: can not play my game development boo hoo...

    HI U.C.Newman,

    Thanks for the reply.

    Glad to know that you were able to solve the problem. Your efforts to solve this problem is appreciated. Feel free to post your request here on the Forums of Windows, we would be happy to help you.

    Thank you.

  • Quick question: change the field names in the contact Muse forms

    I'm sure this is a stupid question, but I can't find how to change the names/labels (those of the email I receive) of my custom fields added. I added a few boxes and in the email that I receive, they are labeled as: "the check box label: I don't know which is which, because I added a couple.

    I use the standard form of the last Muse CC widget. Thank you!

    Thanks for the link.

    Could you please share your with us .muse file to study? Please send it to [email protected]. If your file is more than 30 MB, you can use something like Adobe SendNow or SendThisFile. Don't forget to mention the link to this forum thread in your email (with Air/Muse/operating system version you are using) so that we can identify the file.

  • Impossible to get Graph.DataSource to work in WPF, I (thread question?)

    My chart is work beautifly when I use:

    chartCollection.Append (measure. GHz, measurement.dB);

    But when I try to use this call to the same method, I get nothing on the graph:

    Double data = new double [256];
    ....
    Graph DataSource = data;

    I know not if there is a suspicion, but I declare chartCollection on the main thread, and then pass it on to a different thread to collect data and it draw in real time.

    I could have lived with chartCollection.Append but in this case, I got a lot of data instanteneusly and I want to assign to chart at a time.

    Moreover, it seems that you need about 350 ms differ between each card. Add to not cause exception... but in my case I need to delay in all cases (for data) is not a problem.

    Thank you!

    I'm not very clear on how you mix the table/matrix updates. Here is an example of chart queue adds via the dispatcher (using a class task and assistance as a quick way to simulate the substantive work). You can use any delegate with the dispatcher, so you can assign DataSource in a delegate instead of use the method append on a collection of table.

    public partial class MainWindow : Window {
            private readonly ChartCollection chart = new ChartCollection( );

    public MainWindow( ) {
                InitializeComponent( );

    this.graph.DataSource = chart;

    var worker = new Worker( this.Dispatcher, chart.Append );
                Task.Factory.StartNew( worker.DoWork );
            }

    private class Worker {
                private readonly Dispatcher dispatcher;
                private readonly Action append;

    public Worker( Dispatcher dispatcher, Action append ) {
                    this.dispatcher = dispatcher;
                    this.append = append;
                }

    public void DoWork( ) {
                    for( int i = 0; i <= 360;="" ++i="" )="">
                        double value = Math.Sin( i * Math.PI / 180 );
                        this.dispatcher.BeginInvoke( this.append, i, value );
                        Thread.Sleep( 100 );
                    }
                }
            }
        }

  • thread-&gt; PostUIMessage throws com_error Exceptions

    We have developed a TestStand OI (4.2) including a tracelogger function. Code modules (dll is coded in C++) used in the sequences can send trace messages to the IO by using the function PostUIMessage (see the following code):

    Try
    {
    Get the thread running in the context of the sequence
    thread = seqContext-> GetThread();

    thread-> PostUIMessage (static_cast (UIMsg_UserMessageBase + 4)
    Level
    _bstr_t (Msg),
    (TRUE);
    }
    catch (_com_error & com_error) / * API TestStand throws only this kind of exception * /.
    {
    .....
    }

    It happens that a message is sent every 10ms. Generally this works well both when you run the sequence in the sequence editor and in our IO. But after a rogue from time of 10 minutes to a few hours (depends on the frequency of messages) the PostUIMessage throws a com_error Exception.

    Note: The code is reported as critical section to ensure that it works in multi thread environments too.

    Does anyone have any idea what could be the reason for these exceptions and how to avoid them?

    Thanks in advance

    Peter

    Hi Peter,.

    You wrote that this cycle is about 10ms.

    It's fast!  Normally I use these rates in the threads of work or the threads separated from TS.

    If you have such this in your module or the code sequence file.

    Maybe your variables "seqSontext" or "thread" is not valid.

    Before calling the thread-> PostUIMessage check that everything is valid.

    Hope this helps

    Jürgen

  • Question of SEH Exception occurring on windows server 2012

    Hey, partner,

    One of our client running a desktop application that is developed using .net and some 3rd party controls.

    They had updated to Windows server 2008 R2 to Windows server 2012 R2.

    And using Sql Server 2012.

    They receive the SEH exception on Terminal server environment permanently.

    They restart the server. It is not reproducible on demand.

    Is - this Microsoft provided service packs or hotfixes for this kind of questions?

    Here are the logs of the sample

    Source of the exception: System.Windows.Forms
    Exception type: System.Runtime.InteropServices.SEHException
    Exception message: external component has thrown an exception.
    Exception target site: DispatchMessageW
    -Stack trace-
    to System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run (ApplicationContext context)

    System.Runtime.InteropServices.SEHException
    External component has thrown an exception.

    Thank you

    Srinivas

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)
    *
  • I have answered in my correct security question change my password but I don't always have access.

    I'm so TIRED of trying to reset my password cuz I typed in the wrong... and now can not access. IT IS RIDICULOUS... I did and responded to EVERY THING U asked... and you ALWAYS GIVE me THE RUNAROUND. First THING, it IS I answered my security question CORRECTLY... several times... something wrong in your recordings cuz u keep saying its bad. I want to talk to someone who can fix this... have NO MORE TIME to WASTE on THIS! my account is or hotmail. My password was and is I want to get my mail..!

    Hello CherCastle Cherreegirl,

    This is a public forum, you don't talk to anyone who works for Microsoft, quite ordinary people who enjoy helping others with their respective problems. You should not include any e-mail address or the password (they obviously have been removed for security reasons) in any forum. Imagine the headache that you could have caused if your details had not been withdrawn? You included your e-mail address and the password that would allow anyone who has access to these forums to hack your account. Anyone could also change your password, making it impossible for you to access your account.

    You can try the following links to see if they help:

    https://account.live.com/ResetPassword.aspx

    http://windowslivehelp.com/solution.aspx?SolutionID=6ea0c7b3-1473-4176-b03f-145b951dcb41

    http://TechNet.Microsoft.com/en-GB/security/ff852094.aspx

    This forum post is my own opinion and does not necessarily reflect the opinion or the opinion of Microsoft, its employees or other MVPS.

    John Barnett MVP: Windows XP Expert associated with: Windows Expert - consumer: www.winuser.co.uk | vistasupport.mvps.org | xphelpandsupport.mvps.org | www.silversurfer-Guide.com

  • Another question on the exception of 'Port of SMS already use' in

    I found a lot of discussion about the exception 'SMS Port already use' in. My question is this:. Say an application opens a port SMS and ends abnormally without closing. The unit will continue with the exception of 'Port of SMS already in use' up to reset the signal? is there a way to clean the orifice opened without a reset of the device?

    I need to listen to a specific port and from what I've read, even the datagram method allows one connection.

    Hi scoleman2272

    This KB article explains how to use the connection of datagram. This works for listening, the reverse is also true however for sending.

    I hope this helps.

    Concerning

  • Thread question

    Hello

    I have an application that starts to run in the background on application start, this app starts a new thread to wait on a HttpPush to the server, receiving push a modal window appears and if the user selects Ok I open an app, or ignore the thrust if Cancel is selected in the dialog box.

    The question I have is that the display of the dialog box is pushed, but it seems that the thread does not wait for a reply. That would be because when the screen of the dialog box is pushed it uses a UI Thread?

    You must process the result in the invokelater or use invokeandwait blocking

  • Cp6 - Quiz questions (change the behavior to submit button - quiz numbering)

    Hi all

    This is the first time I built a Uncategorized quiz (I call it an evaluation of knowledge - placed between courses).

    I chose Multiple choice quiz and scored (deselected report answers to the Quiz properties).

    Issues related to the:

    Is there a way to change the Quiz unintuative actions and button controls?

    I want the learner to be able to click on the submit button and move to the next question immediately (like any other rating system I've ever seen)

    The way Captivate: click on submit, display a correct or incorrect and if it is correct, ask to the learner to click on 'Y' or anywhere to continue.

    I have three sets of questions of quiz (for each of the three lessons).

    Is it possible to keep the number of distinct quizzes in each lesson. Currently, there are 4 questions in Lesson 1, 5 in Lesson 2 and 3 in Lesson 3. I want some lesson 1 quiz questions to display 'x 4' NOT 'x 12"'.

    And MOST important...

    Quiz results appears ONLY on the last set of questions. I need a result of quiz for each of the three sets of questions. Is this possible?

    Thank you

    Shawn

    Take a look on:

    http://lilybiri.posterous.com/intermediate-score-slides for your last question

    http://lilybiri.posterous.com/question-question-slides-in-captivate to refine the process in two steps on question slides

    Lilybiri

  • VI Analyzer Questions: Change the default test configuration and screw "Pavilion".

    I have two things I continue to come through in VI Analyzer:

    1. are there in any case to set the default VI Analyzer so that it applies to all projects, I'm working on that?

    I tried to create a task in project A, registration of the configuration and any attempt to open this file in project B, but it says that the file could not be loaded. The reason for my question is that there are a few default options that just add errors that we don't care (e.g. Controls dialog on the façade - 99% of the LabVIEW code that we are working on is called from TestStand as code modules, so the front panel doesn't really count)

    2. can I score / report some screws as 'safe' for parser tests?

    Basically, some screws may fail some perfectly safe way VI Analyzer tests (e.g. non-stanard errors on a 'closing' VI, who doesn't have a case error structure so that the device always gets closed). I wish I had a way to mark the VI kind VI Analyzer would ignore this particular test. This would allow me to have a rule that says something like "before any construction, run the file configuration VI analyzer and make sure there is not error", as opposed to "run VI Analyzer and examine errors, decide whether or not they are important for the VI in question..." ». An extension to this question would be how do I perform a task VI Analyzer before building when the VI Analyzer screw do not accept files cfg for project based tasks.

    Any help would be greately appreciated!

    Thank you

    Shaun

    1. a project oriented .cfg file cannot be transferred between projects.  Could you possibly create a .cfg unrelated to the project file (under the option 'Start a new task' on the first page of the VI Analyzer) and use it?  He would have no file in the list, but it would have all of the configured tests as you want.  And you could start with this on your different projects .cfg file... you would just add screws based on file (on page 2 of the VI Analyzer), rather than have all come to you in a .cfg project-based.

    2. on page 4 VI Analyzer, you can exclude certain tests to run on some screws and save these settings in a .cfg.  This option is also exposed in the VI Analyzer API with VIAn exclude the VI.vi Tests.

  • BSOD from Windows 8 Bootcamp | System thread igdkmd64.sys unhandled exception

    Hello

    I'm on Windows 8 (which is awesome btw) on my Imac on Bootcamp.
    Couple days ago, I installed some Intel graphics... updated via Windows Update. I don't remember the full name of this update, but it has been updated optional. I can't find it in the history of the update or the other

    In any case, after this update my computer was crashing each time to wake up from sleep mode

    Is there any way to uninstall this particular update or return the system to the State where it was before updating?

    File Mididump;
    http://DL.dropbox.com/u/130927/Mididump/032613-37750-01.dmp

    See you soon

    *******************************************************************************
    *                                                                             *
    * Bugcheck analysis *.
    *                                                                             *
    *******************************************************************************

    SYSTEM_THREAD_EXCEPTION_NOT_HANDLED_M (1000007e)
    It is a very common bugcheck.  Usually the PIN address of exception
    the driver/function that caused the problem.

    Nom_image: igdkmd64.sys

    DEBUG_FLR_IMAGE_TIMESTAMP: 50 c 92472

    STACK_COMMAND: .cxr 0xfffff8801b3e88f0; Ko

    FAILURE_BUCKET_ID: X64_AV_igdkmd64 + 23aa4f

    Hello

    The problem driver is the idgkmd64.sys.

    This is associated with an Intel Graphics device.

    If Windows 8 came pre-installed on your computer, contact the computer manufacturer and check the updated drivers for this device.

    You can also go directly to the Intel Web site.

    Microsoft Windows 8 Intel Graphics support FAQ:

    http://communities.Intel.com/docs/doc-19647

    Follow the instructions to identify the device display and download/install the latest drivers.

    Concerning

  • Question - change the stupid root passwords


    I use the same passwords for root for too long to my vm hosts and need to change to improve safety.    The hosts are all added in Vcenter and clustered.    If I change the root password of the individial hosts, is what it's going to break the bond of vcenter?    I know that you type in passwords for root when connecting host to vcenter, but then it installs vpxuser, then I guess it should not occupy root changes after that.   I just wanted to confirm with someone who did this recently.

    (5.0 and 5.1 with Vcenter 5.1 ESXi)

    Hello

    No, the root passwords change does not affect the vCenter.  No link will be broken. It authenticates just the first time that you add the vCenter Server inventory.

    You even change passwords on multiple hosts in a row only to avoid the hassle of Power-Cli scripts.

    Thank you

    Avinash

  • Fixed size thread pool with the exception of the additional tasks, then it must

    Hello
    I have the following code in a simple program (code below)

    BlockingQueue < Runnable > q = new < Runnable > ArrayBlockingQueue (10, false);
    NewPool ThreadPoolExecutor = new ThreadPoolExecutor (1, 10, 20, TimeUnit.SECONDS, q);

    for (int x = 0; x < 30; x ++) {}
    newPool.execute (new threaded());
    }


    My understanding is that this should create a pool of threads that can accept 10 tasks, once there were 10 submitted tasks I should get RejectedExecutionException, however; I see that when I run the code the pool accepts 20 run calls before launching RejectedExecutionException. I am on Windows 7 using Java 1.6.0_21

    Any thoughts on what I am doing wrong?

    Thank you

    -----


    java.util.concurrent import. *;

    public class ThreadPoolTest {}
    Public NotInheritable class threaded implements Runnable {}

    @Override
    public void run() {}
    System.out.println ("wire:" + Thread.currentThread () .getId ());
    try {}
    Thread.Sleep (5000);
    } catch (InterruptedException e) {}
    System.out.println ("Thread:" + Thread.currentThread () .getId ())
    "+"interuptted");
    }
    System.out.println ("output wire:" + Thread.currentThread () .getId ());
    }

    }

    private static int MAX = 10;
    private pool of the executor;


    public ThreadPoolTest() {}
    Super();
    BlockingQueue < Runnable > q is new ArrayBlockingQueue < Runnable > (MAX/2, false);.
    NewPool ThreadPoolExecutor = new ThreadPoolExecutor (1, MAX, 20, TimeUnit.SECONDS, q);

    pool = newPool;
    }



    /**
    @param args
    */
    Public Shared Sub main (String [] args) {}
    Object ThreadPoolTest = new ThreadPoolTest();
    object.doThreads ();
    }

    private void doThreads() {}
    int argued = 0, rejected = 0;
    for (int x = 0; x < MAX * 3; x ++) {}
    try {}
    System.out.println (Integer.ToString (x) + "sending");
    pool. Execute (new threaded());
    submitted ++;
    }
    {} catch (RejectedExecutionException re)
    System.Err.println ("Submission" + x + "rejected");
    rejected ++;
    }
    }

    System.out.println ("\n\nSubmitted:" + MAX * 2);
    System.out.println ("Accepted:" + subject);
    System.out.println ("rejected:" + rejected);
    }

    }

    Interesting, it seems to not dismiss after (size of queue + size of thread pool) supports.

    --
    In fact, it's not interesting. The queue is the buffer and the thread pool size is job tasks.
    He uses the thread pool, the rest first upward, puts it on the queue for a free thread. If both are filled, so there is no space and it rejects submit it.

    Published by: Kayaman April 4, 2011 20:39

  • easy question change text color question

    How do I change the text color?  Neither of these two seem to work...

    messageDisplay_txt.text.color (0xff0000);

    or

    messageDisplay_txt.color (0xff0000);

    ??

    What is the best way to make simple property changes like this?  someone point this noob in the right direction...

    use:

    messageDisplay_txt.textColor = 0xff0000;

Maybe you are looking for

  • Airport Express in client mode to serve Airport Extreme

    Hi guys,. I am struggling with Setup in our business that is pretty special. Our cash register, the Bank Terminal and the control system are all serviced by an Airport Extreme that was configured with care by a dedicated company. The extreme is power

  • Battery runs out quickly...

    Hello Since I've updated my Macbook Air to OS X El Capitan, I started noticing that my battery started to run out very quickly. He used for 10 hours without recharging and now with 100% charging, shows me only 4 hours of battery. Also, I noticed that

  • X 220 problems and displayport

    Hi, I have the Planar: PX2710MW monitor and I have used with my lenovo X 220 for about two months now. He worked until I had to disable the trackpad in the BIOS. When I changed the BIOS return option, the computer will recognize is no longer my monit

  • What digital camcorder is compatible with xp?

    I am looking to buy a digital camcorder that is comatible with windows xp.

  • Toshiba built in camera, Chicony 2.0 USA get the message 'enable camera' in Vista

    Im having trouble with my Tosibas built into the camera. My laptop is about 3 years, the camera used to work... after 5 months of not to use I wanted to use it and it just all just with an error message saying 'The camera' I can see a few people have