→ dy957:看了這個例子就懂了XD 感謝!! 01/13 10:04
你可以這樣子想…static local local其生命週期是整個程式執行期,
所以它相當於global variable,那global variable存在哪呢??
data section!
實例:
int a(int t){
static int num=2;
int pre = num;
num=t;
return pre;
}
thread1{
print a(3); //輸出2
}
thread2{
print a(4); //輸出3
}
//執行順序: thread1 -> thread2
※ 引述《dy957 (dy957)》之銘言:
: 不好意思@@
: 想請問一下 交大99 OS 的第十六題,
: 題目是說multi-thread 可以共享哪些東西
: 可是答案有選到
: "static local variable"
: 可是local variable 不是存放在stack嗎@@
: 而stack是每個thread都有的
: 98年的OS 答案也有給到local variable
: 現在開始不清楚到底是答案錯....還是我觀念錯= ="
: 爬文也找不到一個確定的答案
: 拜託各位版友了...
: 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.187.85