digitalmars.D.learn - receiveTimeout minimum reasonable timeout value?
- Charles Hixson via Digitalmars-d-learn (25/25) May 15 2014 Duration can be specified in nanoseconds, but does it make any sense
- JR (15/21) May 15 2014 I use 0.seconds for such oneshot receive attempts. Snippet:
- Charles Hixson via Digitalmars-d-learn (2/29) May 15 2014 Thanks. That's what I was hoping to hear.
Duration can be specified in nanoseconds, but does it make any sense to have a value of 1 nanosecond? 0? My desire is to check whether a message is in the queue, and then either move it local to the thread, or continue, depending. Secondarily, is there much overhead in calling receiveTimeout frequently? It would minimize the storage in the Tid mailbox, but at the cost of requiring more local storage. As I can only receive one message (if there is one) at a time anyway, it's not clear that I would save much by calling it only once/iteration. The current design is that I have an array of classes to tell to process themselves and I have a local AA of messages, with id#s that say which class instance they are intended for. I could either loop through the array, and then loop receiving messages, or I could receive messages in between processing each instance. The messages received may be intended for any instance in the thread, so they get stacked in an AA of the form: Msg[uint64_t][] msg; Msg is immutable and contains both from and to identifiers, among other things not all of which have been decided. (Well, it's a struct of which all fields are immutable, so I presume the struct counts as immutable, though I haven't yet tested it. I may need to redefine it, but it's intended as immutable.) And the only thing passed to receive is a Msg (or a couple of control values in an enum). As an aside, is it better to have more threads than processors? TDPL seems equivocal about this.
May 15 2014
On Thursday, 15 May 2014 at 18:15:46 UTC, Charles Hixson via Digitalmars-d-learn wrote:Duration can be specified in nanoseconds, but does it make any sense to have a value of 1 nanosecond? 0? My desire is to check whether a message is in the queue, and then either move it local to the thread, or continue, depending.I use 0.seconds for such oneshot receive attempts. Snippet: while (!halt) { if (++readCounter > messageCheckFrequency) { receiveTimeout(0.seconds, &_verbose.fun, &_quiet.fun, &_unknown.fun ); readCounter = 0; } slice = conn.stream.readLine(buf); // ... }
May 15 2014
On Thursday, May 15, 2014 08:21:41 PM JR via Digitalmars-d-learn wrote:On Thursday, 15 May 2014 at 18:15:46 UTC, Charles Hixson via Digitalmars-d-learn wrote:Thanks. That's what I was hoping to hear.Duration can be specified in nanoseconds, but does it make any sense to have a value of 1 nanosecond? 0? My desire is to check whether a message is in the queue, and then either move it local to the thread, or continue, depending.I use 0.seconds for such oneshot receive attempts. Snippet: while (!halt) { if (++readCounter > messageCheckFrequency) { receiveTimeout(0.seconds, &_verbose.fun, &_quiet.fun, &_unknown.fun ); readCounter = 0; } slice = conn.stream.readLine(buf); // ... }
May 15 2014