I now have successfully started the amount of threads I want to start for m开发者_如何转开发y vector clock test program. The next problem seems to be the inter-thread communication; the config files the threads read have a list of IP address (localhost) and port combinations and they should each start listening on the port given to them and at the same time read through the input file, which tells them to either increment their logical clock or send a message to a certain other thread.
If I first create ServerSockets for each thread, the accept() method will apparently block until someone tries to connect to this certain thread via a socket and meanwhile this thread cannot perform other actions that might've been instructed in the input file (which only has lines in the format ("int sendMessageTo int" or "int incrementClock k" - the integers represent lines in the config file, which contains the host & port listing). Is there a way to avoid this?
On linux you can use accept4
instead of accept
and pass SOCK_NONBLOCK
as the flags
parameter.
On POSIX.1-2001, SVr4, 4.4BSD conforming system you can set O_NONBLOCK
using fcntl
.
精彩评论