Base class for multiprocess applications' clients.
It provides a simple interface to fork a ROOT session into server/worker sessions and exchange messages with them. Multiprocessing applications can build on TMPClient and TMPWorker: the class providing multiprocess functionalities to users should inherit (possibly privately) from TMPClient, and the workers executing tasks should inherit from TMPWorker.
Definition at line 23 of file TMPClient.h.
template<class T >
unsigned TMPClient::Broadcast |
( |
unsigned |
code, |
|
|
const std::vector< T > & |
args |
|
) |
| |
Send a message with a different object to each server.
Sockets can either be in an "active" or "non-active" state. This method activates all the sockets through which the client is connected to the workers, and deactivates them when a message is sent to the corresponding worker. This way the sockets pertaining to workers who have been left idle will be the only ones in the active list (TSocket::GetMonitor()->GetListOfActives()) after execution.
- Parameters
-
code | the code of the message to send (e.g. EMPCode) |
args | a vector containing the different messages to be sent. If the size of the vector is smaller than the number of workers, a message will be sent only to the first args.size() workers. If the size of the args vector is bigger than the number of workers, only the first fNWorkers arguments will be sent. |
- Returns
- the number of messages successfully sent
Definition at line 73 of file TMPClient.h.
unsigned TMPClient::Broadcast |
( |
unsigned |
code, |
|
|
unsigned |
nMessages = 0 |
|
) |
| |
Send a message with the specified code to at most nMessages workers.
Sockets can either be in an "active" or "non-active" state. This method activates all the sockets through which the client is connected to the workers, and deactivates them when a message is sent to the corresponding worker. This way the sockets pertaining to workers who have been left idle will be the only ones in the active list (TSocket::GetMonitor()->GetListOfActives()) after execution.
- Parameters
-
code | the code to send (e.g. EMPCode) |
nMessages | the maximum number of messages to send. If nMessages == 0 || nMessage > fNWorkers , send a message to every worker. |
- Returns
- the number of messages successfully sent
Definition at line 248 of file TMPClient.cxx.
This method forks the ROOT session into fNWorkers children processes.
The ROOT sessions spawned in this way will not have graphical capabilities and will not read from standard input, but will be connected to the original (interactive) session through TSockets. The children processes' PIDs are added to the fWorkerPids vector. The parent session can then communicate with the children using the Broadcast and MPSend methods, and receive messages through MPRecv.
- Parameters
-
server | A pointer to an instance of the class that will take control of the subprocesses after forking. Applications should implement their own class inheriting from TMPWorker. Behaviour can be customized overriding TMPWorker::HandleInput. |
- Returns
- true if Fork succeeded, false otherwise
Definition at line 128 of file TMPClient.cxx.
void TMPClient::ReapWorkers |
( |
| ) |
|
Wait on worker processes and remove their pids from fWorkerPids.
A blocking waitpid is called, but this should actually not block execution since ReapWorkers should only be called when all workers have already quit. ReapWorkers is then called not to leave zombie processes hanging around, and to clean-up fWorkerPids.
Definition at line 308 of file TMPClient.cxx.