threadpool

C# thread pool limiting threads

浪尽此生 提交于 2019-11-27 11:20:30
Alright...I've given the site a fair search and have read over many posts about this topic. I found this question: Code for a simple thread pool in C# especially helpful. However, as it always seems, what I need varies slightly. I have looked over the MSDN example and adapted it to my needs somewhat. The example I refer to is here: http://msdn.microsoft.com/en-us/library/3dasc8as(VS.80,printer).aspx My issue is this. I have a fairly simple set of code that loads a web page via the HttpWebRequest and WebResponse classes and reads the results via a Stream . I fire off this method in a thread as

ThreadPool max threads

こ雲淡風輕ζ 提交于 2019-11-27 11:05:31
问题 I've got some trouble with .NET's ThreadPool (.NET 4). I've read that by default .NET has a limit of 25 threads per processor, but according to forum posts on SO and on other places, I can increase the limit with the below code. void SetThreads(int threads) { ThreadPool.SetMaxThreads(threads, threads); ThreadPool.SetMinThreads(threads, threads); } However, when I set the above to some arbitrarily high number, for example, 2000, and queue ~1000 items, I still only have ~33 threads running (

C# - ThreadPool vs Tasks

扶醉桌前 提交于 2019-11-27 10:47:14
As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool. Which one is more efficient and less resource consuming? (Or just better overall?) The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible. The implementation uses a TaskScheduler object to control the handling of tasks. This has virtual methods that you can override to create your own task handling. Methods include

c++ work queues with blocking

好久不见. 提交于 2019-11-27 09:38:09
This question should be a little simpler than my last few. I've implemented the following work queue in my program: Pool.h: // tpool class // It's always closed. :glasses: #ifndef __POOL_H #define __POOL_H class tpool { public: tpool( std::size_t tpool_size ); ~tpool(); template< typename Task > void run_task( Task task ){ boost::unique_lock< boost::mutex > lock( mutex_ ); if( 0 < available_ ) { --available_; io_service_.post( boost::bind( &tpool::wrap_task, this, boost::function< void() > ( task ) ) ); } } private: boost::asio::io_service io_service_; boost::asio::io_service::work work_;

Ensuring task execution order in threadpool

风流意气都作罢 提交于 2019-11-27 09:12:55
问题 I have been reading about the thread-pool pattern and I can't seem to find the usual solution for the following problem. I sometimes want tasks to be executed serially. For example, I read chunks of text from a file and for some reason I need the chunks to be processed in that order. So basically I want to eliminate concurrency for some of the tasks . Consider this scenario where the tasks with * need to be processed in the order they were pushed in. The other tasks can be processed in any

How to catch exceptions from a ThreadPool.QueueUserWorkItem?

别说谁变了你拦得住时间么 提交于 2019-11-27 07:33:04
I have the following code that throws an exception: ThreadPool.QueueUserWorkItem(state => action()); When the action throws an exception, my program crashes. What is the best practice for handling this situation? Related: Exceptions on .Net ThreadPool Threads If you have access to action 's source code, insert a try/catch block in that method; otherwise, create a new tryAction method which wraps the call to action in a try/catch block. You can add try/catch like this: ThreadPool.QueueUserWorkItem(state => { try { action(); } catch (Exception ex) { OnException(ex); } }); If you're using .Net 4

Creating a thread pool using boost

狂风中的少年 提交于 2019-11-27 07:08:04
Is it possible to create a thread pool using boost's thread? i was looking all over boost's libs and I couldn't find a thread pool manager (or something like that)... Is there a way to do it? tnx! There is an unofficial (yet) threadpool in boost. But it's not a problem to implement one yourself especially if great genericity is not a primary goal. Idea: your threadpool can be parametrized with TaskType type and the number of workers. The TP must be given the handler function which takes TaskType. TP contains a queue of added tasks. The real thread function just takes a task from the queue and

C++ Thread Pool [closed]

最后都变了- 提交于 2019-11-27 06:20:50
What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)? Please provide either your own example code or a link to example code usage. I think it is still not accepted into Boost, but a good staring point: threadpool . Some example of usage, from the web site: #include "threadpool.hpp" using namespace boost::threadpool; // Some example tasks void first_task() { ... } void second_task() { ... } void third_task() { ... } void execute_with_threadpool() { // Create a thread pool. pool tp(2); // Add some tasks to the pool. tp.schedule(

Android - Async Task behavior in 2.3.3 and 4.0 OS

旧街凉风 提交于 2019-11-27 06:18:29
问题 I am testing an application where we have a list view with list of images retrieved over network. When i run the application on android device 2.3.3 (WIFI speed 512 KBPS) and check the DDMS (Thread Viewer), the number of threads keeps increasing till 50 from 25. But when i test the same application on device 4.0 (WIFI speed 5 MBPS), number of threads did not increase. Can anyone help me understand why this is happening ? Is it due to android OS difference or any other reason ? Thanks in

ThreadPoolExecutor with corePoolSize 0 should not execute tasks until task queue is full

China☆狼群 提交于 2019-11-27 06:13:15
问题 I was going through Java Concurrency In Practice and got stuck at the 8.3.1 Thread creation and teardown topic. The following footnote warns about keeping corePoolSize to zero. Developers are sometimes tempted to set the core size to zero so that the worker threads will eventually be torn down and therefore won’t prevent the JVM from exiting, but this can cause some strange-seeming behavior in thread pools that don’t use a SynchronousQueue for their work queue (as newCachedThreadPool does).