threadpool

Asynchronous socket reading: the initiating thread must not be exited - what to do?

不问归期 提交于 2019-12-04 05:58:48
I have a NetworkStream which I read asynchronously (using async/await) await Task<int>.Factory.FromAsync((cb, state) => stream.BeginRead(buffer, offset, readLen - offset), stream.EndRead, null); Unfortunatly, an io exception sometimes occurs: "The I/O operation has been aborted because of either a thread exit or an application request." I believe I hit a requirement documented in Socke.EndReceive: http://msdn.microsoft.com/en-us/library/w7wtt64b.aspx . Which states: All I/O initiated by a given thread is canceled when that thread exits. A pending asynchronous operation can fail if the thread

Is it possible for two ExecutorServices to share a thread pool?

被刻印的时光 ゝ 提交于 2019-12-04 05:50:12
I've got a collection of records to process, and the processing can be parallelized, so I've created an ExecutorService (via Executors#newCachedThreadPool() ). The processing of an individual record is, itself, composed of parallelizable steps, so I'd like to use another ExecutorService . Is there an easy way to make this new one use the same underlying thread pool? Is it even desirable? Thanks. Yuval Adam To answer your question: no , two ExecutorService objects cannot share a thread pool. However you can share an ExecutorService between your objects, or alternatively create several Executors

Default TaskCreationOptions in Task.Run

孤街浪徒 提交于 2019-12-04 05:08:18
Why the default value for CreationOptions of a Task created using Task.Run is DenyChildAttach rather than None ? Has it anything to do with making work with the new async and await in C# 5.0 simpler (by preventing you from escaping current scheduler of current context I guess)? Stephen Toub explains this well in his blog post on the subject . Parent and child tasks are somewhat common when using Task s in a parallel fashion. Note that when a parent Task has a child, the parent's completion semantics change subtly. Parent/child tasks are almost never used when using Task s in an async fashion.

Single thread pool vs one thread pool per task

断了今生、忘了曾经 提交于 2019-12-04 04:40:20
问题 I want to use concurrency in Java to make requests to an online API, download and parse the response documents, and load the resulting data into a database. Is it standard to have one pool of threads in which each thread requests, parses, and loads? In other words, only one class implements Runnable . Or is it more efficient to have, say, three different pools of threads, with the first pool of threads making the requests and pushing them to a queue, the second pool of threads polling from

A ThreadPool library in C++

左心房为你撑大大i 提交于 2019-12-04 03:37:39
问题 I am looking for a good and stable threadpool library for C++ that's fairly well documented. I know about the Native Windows thread pool API and the newer Vista Thread Pool API, however my program requires some backward compatibility, so perhaps an outside library I can provide with the program is better. I have looked into Boost's threadpool and it doesn't look bad at all, unfortunatly it is not very well documented. Does anyone know any other libraries that have a ThreadPool in C++? (for

After FileSystemWatcher fires - Thread Pool or Dedicated thread?

♀尐吖头ヾ 提交于 2019-12-04 03:31:18
问题 I am about to implement the archetypal FileSystemWatcher solution. I have a directory to monitor for file creations, and the task of sucking up created files and inserting the into a DB. Roughly this will involve reading and processing 6 or 7, 80 char text files that appear at a rate of 150mS in bursts that occur every couple of seconds, and rarely a 2MB binary file will also have to be processed. This will most likely be a 24/7 process. From what I have read about the FileSystemWatcher

How to get a second System.Thread.ThreadPool?

喜你入骨 提交于 2019-12-04 03:25:36
问题 If I use the ThreadPool in a nested way, my application hangs: ThreadPool.QueueUserWorkItem((state) => ThreadPool.QueueUserWorkItem(Action)); How to get a second and independent ThreadPool to achieve nesting? 回答1: There is only one single ThreadPool - it's not something you can (or should) make more than one instance of in an application. I don't recommend doing this, but if you really wanted to, you could use multiple instances of your own ThreadPool implementation, such as SmartThreadPool.

What is the C# equivalent of MsgWaitForMultipleObjects?

无人久伴 提交于 2019-12-04 03:14:19
I have a Windows Form with a ListView in Report Mode. For each item in the view, I need to perform a long running operation, the result of which is a number. The way I would do this in native win32 is to create a worker thread for each item (naively; of course I won't create an unbounded number of threads) and then MsgWaitForMultipleObjects() on the array of thread handles. As each calculation finishes, the threads signal and the main UI thread wakes up and updates. In the mean time, we pump messages so the UI thread remains responsive. Can anyone provide an example of how this might work in C

C# How to count managed threads in my AppDomain?

蓝咒 提交于 2019-12-04 03:05:41
Is there a way to find out how many managed thread I use (including ThreadPool)? When I get count of unmanaged threads through GetProcess I have an insane number of it (21 at very beginning) That's not the way it works. Any thread in a managed program can execute managed code, including ones that were originally started as an unmanaged thread. Which most are, the main thread and any threadpool thread starts life executing purely unmanaged code. It thunks into managed code though the kind of gateway provided by Marshal.GetDelegateForFunctionPointer(). Seeing dozens of (otherwise inactive)

ASP.NET HttpContext.Current inside Task.Run

大兔子大兔子 提交于 2019-12-04 00:32:09
I have a following code example that is used in ASP.NET MVC application. The purpose of this code is to create "fire and forget" request for queuing some long running operation. public JsonResult SomeAction() { HttpContext ctx = HttpContext.Current; Task.Run(() => { HttpContext.Current = ctx; //Other long running code here. }); return Json("{ 'status': 'Work Queued' }"); } I know this is not a good way for handling HttpContext.Current in asynchronous code, but currently our implementation not allows us to do something else. I would like to understand how much this code is dangerous... The