2
$\begingroup$

in Programming language course my professor take an example.

Suppose the following code:

int x=initialization();
Thread T1=new computethread(x);
Thread t2=new evaluatethread(x);
...
...
Thread t100=new evaluatethread(x);

threads t1 to t100 needs the initial value of variable x for their computation and t1 need to change the x, which transfer of parameter for computethread, evaluatethread is preferred?

my professor say:

1) call by value result

2) call by ref

is preferred for sending x to computethread, evaluatethread, why call by result or call by name or this order like 2) call by value result, 1) call by ref is not preferred? why he conclude these are better?

$\endgroup$
  • 1
    $\begingroup$ Please don't use words like "Big advanced challenge" in the title of your question. They convey no information at all to anyone who might read the question. $\endgroup$ – David Richerby Oct 17 '14 at 18:07
  • $\begingroup$ Please don't post the same question to multiple sites. $\endgroup$ – svick Oct 18 '14 at 1:28
1
$\begingroup$

Call by reference is cheaper than call by value since you don't need to copy your object. That's why we prefer it when possible. If the thread needs to change its local copy, then you need it to have a copy of its own, which is the same as call by value.

$\endgroup$
  • $\begingroup$ so you means for evaluatethread we select call by ref because it's cheaper? what about first one? $\endgroup$ – T. Jzmod Oct 17 '14 at 18:57
  • $\begingroup$ I think my answer gives enough hints to understand the professor's answer. It is better if you worked it out yourself. $\endgroup$ – Yuval Filmus Oct 17 '14 at 21:22
  • $\begingroup$ DEar @Yuval, for computethread we use call by value result, and for evaluatethread we use call by ref. your answer is not related to this. $\endgroup$ – T. Jzmod Oct 17 '14 at 21:29
  • $\begingroup$ I beg to differ. I haven't spelt the answer on purpose, but it's nearly there. Try to spend more time on the question with the new information in my answer. $\endgroup$ – Yuval Filmus Oct 17 '14 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.