FixedThreadPool vs CachedThreadPool: the lesser of two evils

A CachedThreadPool seems appropriate for your situation as there are no negative consequence to using one for long running threads directly. The comment in the java doc about CachedThreadPools being suitable for short tasks merely suggest that they are particularly appropriate for such cases, not that they cannot be used for long running tasks. The … Read more

multiprocessing.Pool – PicklingError: Can’t pickle : attribute lookup thread.lock failed

multiprocessing passes tasks (which include check_one and data) to the worker processes through a mp.SimpleQueue. Unlike Queue.Queues, everything put in the mp.SimpleQueue must be pickable. Queue.Queues are not pickable: import multiprocessing as mp import Queue def foo(queue): pass pool=mp.Pool() q=Queue.Queue() pool.map(foo,(q,)) yields this exception: UnpickleableError: Cannot pickle <type ‘thread.lock’> objects Your data includes packages, which … Read more

AsyncTask.executeOnExecutor() before API Level 11

If your build target is set to API Level 11 or higher, and you want to specifically use parallel tasks, you will want to start stating that explicitly in your code, akin to: if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) { myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); } else { myTask.execute((Void) null); } http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html

c++ work queues with blocking

Well. That’s really quite simple; You’re rejecting the tasks posted! 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 ))); } } Note that the lock “waits” until the mutex is not owned by a thread. This might already be the … Read more

C# – ThreadPool vs Tasks

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 for instance protected virtual void … Read more

ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew

If you’re going to start a long-running task with TPL, you should specify TaskCreationOptions.LongRunning, which will mean it doesn’t schedule it on the thread-pool. (EDIT: As noted in comments, this is a scheduler-specific decision, and isn’t a hard and fast guarantee, but I’d hope that any sensible production scheduler would avoid scheduling long-running tasks on … Read more