sorry, when i extrat my code i forget to change some words:
main(){
....Handle hCont=CreateFile(....);
hSema=CREATESemaphore(0,1,1,0);
hSemaThr=CREATEMUTEX(0,10,10,0);//so there are only 10 threads at most in the same time
WHILE(regex_search(begin,end,stringmatch,r)){
string s=stringmatch[0];
begin=stringmatch[0].second;
WaitForSingleObject(hSemaThr,INFINITE);
CreateThread(0,0,Grab,(void*)dc,0,0);
}
CloseHandle(hCont);
}
void Grab(void* doc){
......
......
WaitForSingleObject(hSema,INFINITE);
if(!WriteFile(::hCont,lpBuf,(int)strlen(lpBuf),&lpN,0)){
cout < <"can't write file in thread" <