Domanda

I have this algorithm that two threads run at the same time

n = 0

int tmp

do 10 times

    tmp = n
    n = tmp + 1

I know this can get 20, and 10 by each thread executing all the way to the end in sequence, and by one thread loading n into tmp, then the other finishing will result in 10.

I'm just not sure if this can get 2.

È stato utile?

Soluzione

I would say that n will be >= 10 and <= 20, and that I really don't see how you could get anything < 10. But the whole thing is so wrong, I don't even know why I am answering :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top