Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15498
| From | Christopher Pisz <someone@somewhere.net> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? |
| Date | 2012-04-20 17:48 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <jmsp40$la$1@dont-email.me> (permalink) |
| References | <9cfd1d2a-8b1e-47b3-84b0-7de22dadcdcc@b14g2000vbz.googlegroups.com> <jmq4au$21h$1@dont-email.me> <62c8871a-a172-46c2-9722-daf155849fdb@c28g2000vbu.googlegroups.com> |
On 4/20/2012 12:43 PM, K. Frank wrote: SNIP > But now suppose two of the threads block (for example, by > making a synchronous database call). If I understand things > correctly, in the io_service case only two threads will be > actively running, leaving two processor cores idle. In > contrast, the IO Completion Port will release two more threads > (from its thread pool of twenty) to work on the packet queue, > keeping all four cores busy. > > To me that's the key issue. You have the ability to have > more threads in the thread pool than cores so that the cores > keep busy even if some threads block, while (usually) only > having as many actively running threads as cores, thereby > avoiding unnecessary context switching. > > This feature of IO Completion Ports has always struck me as > both clever and practical. I see now. As you say below, I would think the boost io_service would mimic that behavior on Windows. I'd have to write a test case. Let me know what your results are if you write one. I wouldn't expect that to be the case on non-windows platforms. >> ... >> You can also use a thread_group, but I haven't tried that yet. I just >> create an array of threads. > > Just thinking out loud here ... > > So (using C++11 std::thread terminology here) if an > IO-Completion-Port-like construct used a condition_variable > to synchronize the thread pool's access to the "packet" > queue, then we would want something like: > > if ( > "packet added to empty queue"&& > "active threads< concurrency_value" > ) cv.notify_one(); > > and > > if ( > "active threads falls below concurrency_value"&& > "queue not empty" > ) cv.notify_one(); > > Of course, this is just suggestive. I don't pretend to know > how to implement an IO Completion Port without it already being > built into the operating system. > > Coming back to io_service, it looks like it _does_ offer > concurrency_value functionality on windows. One of the > io_service constructors takes a "concurrency_hint" > argument: > > io_service (std::size_t concurrency_hint); > > I am willing to bet that this argument is ignored on > non-windows platforms, and that on windows platforms > io_service is implemented using an IO Completion Ports, > and that concurrency_hint is passed to the IO Completion > Port as its concurrency value. (I haven't verified it, > but it looks true to me.) > > This is altogether reasonable. I can use io_service across > platforms, and on windows (but only on windows) I get the > benefit of the concurrency-value optimization. > > Unfortunately this also suggests that implementing the > concurrency-value functionality on top of "standard" > synchronization primitives (without os support) isn't > so easy (because otherwise the boost guys might have > done it). I also believe you are correct in that I would not expect that behavior from non-Windows platforms, because as far as I know, it is only available on Windows. I remember when I was doing a socket library for Linux that I couldn't find a thing. > So, two questions: > > Is it practical to implement the IO Completion Port > concurrency-value feature using "standard" primitives? I wouldn't dare try to do something similar myself, just because of risk/cost/benefit. Maybe for a purely academic just for fun exercise. > Does anyone have any historical color or insight into the > thinking of the Boost.Asio developers on this issue? Good question for the boost mailing list. You can get to it using Gmane. They have instructions on the boost site. The response rate isn't great though. Most talk is about the C++11 features.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? "K. Frank" <kfrank29.c@gmail.com> - 2012-04-18 16:46 -0700
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? Christopher Pisz <someone@somewhere.net> - 2012-04-19 17:41 -0500
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? "K. Frank" <kfrank29.c@gmail.com> - 2012-04-20 10:43 -0700
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? Christopher Pisz <someone@somewhere.net> - 2012-04-20 17:48 -0500
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? "K. Frank" <kfrank29.c@gmail.com> - 2012-04-20 19:53 -0700
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? Nobody <nobody@nowhere.com> - 2012-04-22 03:17 +0100
Re: Is there (semi-) portable IO-Completion-Port-like functionality in C++ land? Christof Meerwald <NOSPAM-seeMySig+uzk5+@usenet.cmeerw.org> - 2012-04-22 20:09 +0000
csiph-web