的局部結構這是我的結構:如何將結構複製到一個線程
struct example {
int c=0;
char buf[10];
}
我有這種類型在main()
...
struct example *ex=malloc(sizeof(*ex));
...
分配並傳遞給線程的結構
...
pthread_create(&id[i], NULL, t_func, ex);
...
pthread_create被調用到main的子項中。
t_func
是:
void *t_func(void* args) {
struct example *extmp = args;
....
如何創建在每一個線程本地struct example
,並複製到它的結構和args的值是多少?我需要它,如果我修改本地結構的一個字段,這將不會在其他線程中看到。我見過的其他類似的問題,但我還沒有找到我的答案...
難道你不能只爲每個線程malloc另一個線程並傳入*指針,就像你現在正在做的一樣?你真的需要複製它嗎? – 2012-01-27 20:54:29
@MartinJames是的,我需要複製,因爲我需要每個線程的鏡面結構 – rschirin 2012-01-27 23:36:52
@MartinJames你能解釋一下你是什麼意思嗎?你不能只爲每個線程malloc另一個線程並傳入*指針嗎?也許在僞代碼中,謝謝 – rschirin 2012-01-28 00:57:19