(ACE)執行緒專用儲存

2021-08-23 13:04:40 字數 1408 閱讀 8612

關於執行緒儲存 無非就是兩種儲存方式:一種是 專用儲存,另一種是 共享儲存

在 專用儲存 用 ace 內 的 ace_tss模板類可以實現一次全域性宣告的 專用儲存方式。例子

class datatype 

public: 

datatype():data(0){} 

void increment() 

void set(int new_data) 

void decrement() 

int get() 

private: 

int data; 

ace_tssdata; 

static void* thread1(void*) //加後等於 15

data->set(10); 

ace_debug((lm_debug,"(%t)the value of data is %d \n",data->get())); 

for(int i=0;i<5;i++) 

data->increment(); 

ace_debug((lm_debug,"(%t)the value of data is %d \n",data->get())); 

return 0; 

static void * thread2(void*) //加後等於 105

data->set(100); 

ace_debug((lm_debug,"(%t)the value of data is %d \n",data->get())); 

for(int i=0; i<5;i++) 

data->increment(); 

ace_debug((lm_debug,"(%t)the value of data is %d \n",data->get())); 

return 0; 

int main(int argc, char*argv) 

//spawn off the first thread 

ace_thread_manager::instance()->spawn((ace_thr_func)thread1,0,thr_new_lwp|  

thr_detached); 

//spawn off the second thread 

ace_thread_manager::instance()->spawn((ace_thr_func)thread2,0,thr_new_lwp| thr_detached); 

52 //wait for all threads in the manager to complete. 

ace_thread_manager::instance()->wait(); 

ace_debug((lm_debug,"both threads done.exiting.. \n")); 

利用ACE管理執行緒

我所接觸的ace中對執行緒操作的類主要有兩個,乙個是ace thread,另乙個為ace thread manager ace thread能夠管理所有執行緒,只要你掌握有需要被管理的執行緒的id ace thread manager的乙個物件能夠管理該物件所建立的執行緒。建立乙個執行緒的函式有 通...

ACE多執行緒伺服器

ace adaptive communication environment 它是乙個物件導向的 跨平台的 開放原始碼的網路程式設計基礎設施框架。ace 是由加利福尼亞大學irvine分校的douglas c.schmidt 博士主導開發的,是一種跨平台可編譯的網路程式設計api,並隨後在工業界中發...

基於ACE應用程式設計框架 執行緒池 ACE

private imanager manager shutdown 0 workers lock workers cond workers lock 執行緒處理函式 int svc void choose a worker.worker worker 0 這對大括號中的 從worker執行緒池中獲取...