我在做Dll,我还需要用到多线程 ,我想用关键代码同步线程 ,我是在dll的dllmain里初始化critical_section的,我在dll的其它输出函数里EnterCriticalSection的,为什么我开始时通过汇编窗口发现CRITICALSECTION变量确实初始化过了,但在别的函数里申请时发现它又变成全零了。能帮我解决一下吗?谢谢!!
我是在exe文件里建的新线程,线程函数在Dll里,我是不是不能在Dll里做线程同步啊?
谢谢各位高手!

解决方案 »

  1.   

    oh you can , The method you choosed is called The Critical Section which usually be used as resourse sharing , if you merely want to synchronize your threads ,Mutex or Semaphore is your best opt.
      

  2.   

    by the way do not initialize the critical section again when new thread is created in dll main function.dllmain( reason )
    {
       if( reason  == process_init )
       {
            //init cs
       } 
    }
      

  3.   

    thank you very much!NetDNASupport!
    but if I use other methord to synchronize threads,it must be too slow
    even more I just creat one Processor