请教 ServerSocket 回调函数的数据保护问题
ServerSocket 的 ClientRead 事件在有数据到达的时候触发。
如果处理时间过长,那么就会出现函数重入的情况。
为此需要对一些全局变量做 数据同步 的保护。
查资料知道有一个 TCriticalSection 用之
.h 里
TCriticalSection *CriticalSection;
.cpp
FormCreate 里
CriticalSection = new TCriticalSection;
ServerSocket1ClientRead 里
CriticalSection->Acquire();
//处理全局变量、数据代码
CriticalSection->Release();
但是经测试,发现 CriticalSection 并未起作用。
不知道 CreateSemaphore()、CreateEvent()、WaitForSingleObject()、ReleaseSemaphore()、SetEvent()等等 是否只能用在 线程中?
请用过的 XDJM 不吝指教
谢谢!!