473,473 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Tasks with PFX

I have been watching an MSDN video on the PFX Task class and have a
question.

Here is my scenario:

TcpListener waits on incoming connections. Once a new connection is
established, a new Task will be created.
So, for my example, 8 connections have been established almost all at
the same time (8 Tasks object).
If my server is a dual core (for arguments sakes, 4 Tasks per CPU) does
each Tasks have to complete on each CPU, before the next one can start?

The video seemed to indicate that only 1 Thread per CPU would be
created:

CPU 1:

Task 1
Task 2
Task 3
Task 4

CPU 2:

Task 5
Task 6
Task 7
Task 8

Task 1 would be a Thread ID 1 for example, and would have to complete
before Task 2 could start (It would have Thread ID 1)

I was under the impression the Tasks would represent a seperate thread,
but manage which CPU they would be executed on, but watching the MSDN
video indicates that the amount of CPU's dictates how many threads get
created (rather than 8 threads, we would get 2 re-used threads)

Hopefully this isn't too complicated and someone cna help me out.

Thanks in advance,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Oct 31 '08 #1
3 2969
On Fri, 31 Oct 2008 07:11:20 -0700, Steven Blair
<st**********@btinternet.comwrote:
I have been watching an MSDN video on the PFX Task class and have a
question.
What "MSDN video on the PFX Task class"?
[...]
I was under the impression the Tasks would represent a seperate thread,
but manage which CPU they would be executed on, but watching the MSDN
video indicates that the amount of CPU's dictates how many threads get
created (rather than 8 threads, we would get 2 re-used threads)

Hopefully this isn't too complicated and someone cna help me out.
I would say that until .NET 4.0 comes out, it will be difficult to say for
sure what the defined behavior for the Parallel Extensions for .NET
classes will be. Even if the library currently does one thing, it might
do something different by release, depending on what's found during the
preview.

Now, that said...if you've watched a video that says that tasks get
queued, with the maximum number of concurrently running tasks limited to
the number of CPUs, I would say that's the behavior you should expect.
That's certainly a reasonable implementation; rather than having all the
tasks competing with each other for the CPU, limiting the number of
executing tasks so that each can optimally use the CPU, maximizing
throughput.

Pete
Oct 31 '08 #2
This video:

http://channel9.msdn.com/posts/Danie...k-and-friends/

Yeah I was really looking for clarification, and perhaps, this new API
is not what I need.
If Task1 must be completed before Task completes, this really throw out
using PFX for me (each Task should be able to run concurrently).

I was under the impression the PFX would let my threads running over
multi CPU's rather than queue up threads to process them more
efficiently.

Just as another question, my current code uses the ThreadPool. If I
kicked off 8 threads from this, would they automatically be assigned to
differen CPU's for free (so to speak)?

*** Sent via Developersdex http://www.developersdex.com ***
Oct 31 '08 #3
On Fri, 31 Oct 2008 10:42:37 -0700, Steven Blair
<st**********@btinternet.comwrote:
This video:

http://channel9.msdn.com/posts/Danie...k-and-friends/
Sorry, don't have time to watch it now (25 minutes!). I'll just assume it
says what you say it says (I haven't spent much time with the Parallel
Extensions, don't even have documentation handy for it right now).
Yeah I was really looking for clarification, and perhaps, this new API
is not what I need.
If Task1 must be completed before Task completes, this really throw out
using PFX for me (each Task should be able to run concurrently).
Any particular reason they have to run concurrently?
I was under the impression the PFX would let my threads running over
multi CPU's rather than queue up threads to process them more
efficiently.
My impression of the PFX is that the library is intended to make it easier
to write true parallelized algorithms without worrying so much about the
implementation of the parallelism and to maximize performance. Only by
restricting the number of concurrently running tasks can it do the latter.
Just as another question, my current code uses the ThreadPool. If I
kicked off 8 threads from this, would they automatically be assigned to
differen CPU's for free (so to speak)?
Even ThreadPool doesn't give you that kind of control over the threads.
You queue work items (i.e. "tasks"), not threads.

If you queue eight tasks all at once, and they run long enough, then
yes...eventually you'll get eight threads all running at once. By default
in .NET 2.0, a new thread is created only every half second, and you start
with one idle thread per processor. So, assuming a two-CPU system, it
would take another three seconds to add six more threads. If the first
task completes in less than three seconds, you won't get eight threads
working at the same time.

If you're doing i/o, and can guarantee that any given operation isn't
going to tie up a ThreadPool thread for _too_ long (i.e. longer than a
minute or so), then ThreadPool might well be reasonably appropriate. But
if you're writing CPU-bound code and have any interest at all in
maximizing throughput, then the PFX Task behavior may well be better.

As a general rule, it's counter-productive to insist on concurrently
executing threads for a group of related tasks. If for some reason you
actually have a legitimate exception to this rule, then you'd probably
want to avoid PFX, since in that case you'd have some goal that's mutually
exclusive with the most efficient use of the CPU.

Pete
Oct 31 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dominic | last post by:
Just in case someone is interested. I came up with this solution since my previous posting. Maybe you've got some other ideas or critcism. I'll listen ;-) Ciao, Dominic P.S. Python is...
2
by: meng | last post by:
is it possible to use a single connection object shared by several tasks where each task is handled by a thread? these tasks call stored procedures that return record sets, no editing, update or...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
7
by: pfa | last post by:
I have a udf which returns a table. I was hoping to access the NEXTVAL from a sequence to affect the logic flow and consequently the return result. I'm using a LANGUAGE C type function. Here's...
6
by: Sivaraman.S | last post by:
Hi, I have a doubt in .net. Hope u could solve the problem. When u r free plz consider this doubt. I have created a component to run End of Day Tasks. Hope u know how much time it takes to...
4
by: Beren | last post by:
Hello I'm trying to use Cache expiration and its callback feature to easily add automated tasks programmatically. The task should be run when the Cache object expired The problem I'm facing...
3
by: Bob Day | last post by:
VS 2003, vb.net, sql msde... The help is pretty empatic that you cannot pass parameters to a thread. The sample below is from help, showing you to set up variables in the TasksClass, and assign...
1
by: Derekc25 | last post by:
Hi, I'm trying to create macros for an excel sheet, where i have different actions required for different tasks, each action has its own individual time, I place a "X" in the cell underneath each...
1
by: Joshua Gardner | last post by:
I'm brand new to USENET so please bear with me. I'm writing a specialized to-do list app. I'm using Django but this is not a question about Django. It has to have recurring tasks set by the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.