I have a process that I think would work with parallel_while pretty good, but It's not behaving how I'd expect.
First the process: I have a server that sits and listens to requests, for the sake of this example, lets say the requests come in on a named pipe (I've also used sockets for this, it all depends on what the customer wants - some secure places won't allow ANY sockets open even for communication on the same machine). When a reqest come in, the server then does some complicated computation and returns the answer to the client.
I thought this would be great for a parallel while. I have the pop_if_present function listen for a connection on the named pipe or socket (blocking) and when it gets something from the client, it returns a true and in populates the argument_type& with the request and a pointer to the client to send the reply to.
The body of the while loop takes data, does the compuation, sends the reply when it's done and the closes the socket.
the pop_if_present function looks like this
NamedPipe* Pipe=new NamedPipe(PipeName);
printf("creating pipe "); fflush(stdout);
printf("reading pipe "); fflush(stdout);
printf("dispatching %s ",Command.c_str()); fflush(stdout);
and the body of the while loop looks like thisvoid operator()(Message* pMessage) const
printf("hello! "); fflush(stdout);
printf("receiving command ");
printf("sending result '%s' ",Result);
When I run the program, it listens on the pipe and the clients can properly send data to it, however, it seems that the body of the loop is never called. I get all the debug output for creating the pipe, reading the pipe, and dispatching the message. But I don't even get the "hello" printed from the body of the while loop.
Any ideas? Is there a smarter way to do this? I'd rather not use raw threads if i can avoid it. The work that the body of the while loop does will use tbb algorithms too so I'd like to keep it all set up so that tbb's task scheduler does the scheduling.
Basically, I'll have a big processing engine running tbb that will accept reqests from clients to solve hard problems. The order that the client's requests get processes doesn't matter too much, although a queue is probably the best so that no client gets shut out for too long. The pattern that requests are made is unpredictable, it all depends on how many users will be running clients.