我有一個線程和進程的內存地址有關的問題。的問題是: - 在 正常呼叫一樣線程的堆棧地址和主進程
int func(int a, int b){
int c;
c = a + b;
return c;
}
int main(){
int ret = func(a,b);
return 0;
}
在上面的函數調用函數func,函數變量a和b將得到存儲在堆棧中。請糾正我,如果我錯了。
現在另一種情況是當我們從主進程創建線程時。
void * func(void *dummy_ptr){
int c;
c = a + b;
pthread_exit();
}
int main(){
pthread_t id;
int ret = pthread_create(&id, NULL, & func(), NULL);
return 0;
}
我的問題是pthread_create的變量將被存儲在哪裏。它是否存儲在主堆棧或線程堆棧中。
您的示例不會編譯,因爲您錯過了聲明'a'和'b'。 – alk