Can we execute two different statements together? Suppose these are the two statements
x += 2*y;
y = 2*x+3*y;
Here we can see the statements are dependent. So can we execute them concurrently?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, you could calculate the overall change to the two variables and go to that directly (provided you take a snapshot of the values so that there’s no actual data dependencies between them; did you know that a number of microprocessors will do this automatically, though only where the code is free of data dependencies?). Using your example and inventing a little fake syntax:
But you can’t do this in Javascript as the language doesn’t support direct parallelism. (That has its advantages, of course. For one thing, it massively simplifies the semantics of the code, so allowing implementations to pull of tricks like this behind the scenes if they can prove its correct.) It would also be pointless for something as trivial as this example; there’s quite a lot of overhead involved (in general) in spinning up extra threads, and when it gets up to the point of being worthwhile, it’s usually very difficult to simplify the expressions to the point where you can make them hazard-free.