Say you have Thread A trying to push 20 and Thread B trying to push 30 into the stack, and Thread A got the time slice first.
假设线程 A 试图把 20 压入堆栈,线程 B 试图压入 30,而线程 A 先获得了时间片。
In this example, when main called function1 , it pushed the values for c, then b, then a onto the stack.
在这个例子中,当main调用function1时,它将c的值压入堆栈,然后压入b的值,最后压入a的值。
So, the code loops back, points to the proper top pointer (which was changed because of Thread b), invokes CAS, and is done with pushing 20 into the stack.
因此,代码回到循环的开头,指向正确的top指针(线程b修改后的),调用CAS,把20压入堆栈后结束。
应用推荐