c++ - send over IP immediately on different thread -


this impossible, i'm going ask anyways. have multi-threaded program (server) receives request on thread dedicated ip communications , passes on worker threads work, have send reply answers client , send when finished, little delay possible. using consumer/producer pattern , placing replies on queue ip thread take off , send client. this, gives me no guarantee when going happen, ip thread might not scheduled time soon, cannot know. makes client, blocking call, think request has failed, not point.

due fact unable make changes in client, need solve sending issue on side, problem i'm facing not wish start sharing ip object (currently on 1 thread) worker threads, things overly complicated. wondered if there way can use thread sync mechanisms ensure moment worker thread finished, ip thread execute send reply client?

will manual/autoreset events me or these not guaranteed wake thread immediately?

if need sent immediately, best bet bite bullet , start sharing connection object. lock before accessing it, of course, , sure think you'll if send buffer full (the connection thread need deal sending portion of message didn't fit first time, or worker thread blocked until client accepts of data you've sent). may not difficult if clients have 1 request running @ time; if that's case can pass ownership of client object worker thread when begins processing, , pass when you're done.

another option using real-time threads. details vary between operating systems, in cases, if thread has high enough priority, scheduled in if becomes ready run, , preempt other threads lower priority until done. on linux can done sched_rr priority class, example. however, can negatively impact performance in many cases; crashing system if thread gets infinite loop. requires administrative rights use these scheduling classes.

that said, if scheduling takes long enough client times out, might have other problems load. should put number on how fast response needs - there's no end of things can if want speed response, there'll come point doesn't matter anymore (do need response in tens of ms? single-digit ms? hundreds of microseconds? single-digit microseconds?).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -