首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

多线程单链表解决方法

2013-03-13 
多线程单链表在一个dll中 我有个链表 使用双线程。第一线程可控制第二线程不可控制在第一线程中控制链表的

多线程单链表
在一个dll中 我有个链表 使用双线程。  第一线程可控制  第二线程不可控制  
在第一线程中控制链表的删除 增加  销毁
第二个线程中只是读取链表储存的指针  
怎么才能保证链表安全性。 
我一直是在第二个线程中读取储存的指针出错。。。 求详细方法
[解决办法]
 Thread1:   
  EnterCriticalSection(   &g_csInt   );   
  EnterCriticalSection(   &g_csUint   );   
  for   (   intLoop   =   0;   intLoop   <   100;   intLoop++   )   
  {   
  g_uintArray[intLoop]   =   g_intArray[intLoop];   
  }   
  LeaveCriticalSection(   &g_csInt   );   
  LeaveCriticalSection(   &g_csUint   );   
  Thread2:   
  EnterCriticalSection(   &g_csInt   );   
  EnterCriticalSection(   &g_csUint   );   
  for   (   intLoop   =   0;   intLoop   <   100;   intLoop++   )   
  {   
  g_uintArray[intLoop]   =   g_intArray[intLoop];   
  }   
  LeaveCriticalSection(   &g_csInt   );   
  LeaveCriticalSection(   &g_csUint   );   


http://blog.chinaunix.net/uid-24977843-id-376654.html

热点排行