我已經調用了使用輔助線程的方法。 從方法內部我需要從主線程調用一個方法。從輔助線程使用主線程的調用方法
這裏是結構
void main_thread_method()
{
}
void secondary_thread_method()
{
//do something here
call main_thread_method() here using main thread
}
pthread thread1;
pthread_create (&thread1, NULL, (void *) &secondary_thread_method, NULL);
pthread_join(thread1);
由於一個線程中的數據可以從同一進程中的另一個線程訪問,所以我沒有看到問題所在?你想將控制轉移到另一個線程進行一些計算嗎?在這種情況下,檢查信號和條件變量。 –
@All:在Objective C/C++中,有一個API可以在輔助線程中使用主線程調用方法。實際上,我需要調用gtkWindow對象,該對象只能從主線程調用。 – boom