Performance tuning: writing data to multiple pipes
Now I'm doing it in a single thread:
for(unsigned int i = 0; i < myvector.size();)
{
tmp_pipe = myvector[i];
fSuccess = WriteFile( tmp_pipe, &Time, sizeof(double), &dwWritten, NULL );
if(!fSuccess)
{
myvector.erase(myvector.begin()+i);
printf("Client pipe closed\r\n");
continue;
}
fSuccess = WriteFile( tmp_pipe, &BufferLen, sizeof(long), &dwWritten, NULL );
if(!fSuccess)
{
myvector.erase(myvector.begin()+i);
printf("Client pipe closed\r\n");
continue;
}
fSuccess = WriteFile( tmp_pipe, pBuffer, BufferLen, &dwWritten, NULL );
if(!fSuccess)
{
myvector.erase(myvector.begin()+i);
printf("Client pipe closed\r\n");
continue;
}
i++;
}
And the result is that the first pipe
gets data fastest ,and the last pipe
slowest.
I'm thinking of doing it in separate threads so each pipe
is equally processed.
But how can I run a specific function of thread asynchronously(the main thread should get return immediately) in c/c++?