Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:57:29+00:00 2026-05-22T12:57:29+00:00

I am studying task parallel library for .NET (TPL) , I am trying to

  • 0

I am studying task parallel library for .NET (TPL) , I am trying to understand how it works , I understand the idea of work stealing , but I can’t understand why we use duplicating queue and How it works ?

when new task is created , whom specify which thread should take it and put it in its task queue ?

can you help me ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:57:30+00:00Added an answer on May 22, 2026 at 12:57 pm

    Imagine you were implementing the TPL yourself and used ordinary non-duplicating work-stealing queues. So, for each queue, you have one thread that pushes to and pops from the tail of the queue and multiple threads that can take from the head of the queue (called thieves in the paper). Because you want to make sure that every task that is added to the queue is removed exactly once (either by popping or by taking) you have to use locking in each of the three operations.

    In a way, it seems quite wasteful to lock on push and pop, when you know only one thread is going to use those operations. But there’s nothing you can do about it, if you want to be sure the queue behaves correctly.

    Your library works, but you realize what often happens is that you are waiting for a task, which was not even started yet. So, what about running it synchronously in the current thread? You could do that, but the problem is that the task is in some queue and you can’t safely and quickly remove it from there. What you can do though is to add a flag to the task, indicating its state, and accessing the flag in a thread-safe manner.

    This way, if you dequeue the task eventually, you won’t run it, because you know it is already running or even finished. What about the queue? We said we wanted to make sure we remove the task from the queue exactly once. But this is no longer required: if we remove some task twice, it doesn’t matter, because the task is going to take care of it itself and will actually start only once.

    But this means we can remove the locks from pop and push, resulting in a duplicating queue, which is faster than normal work-stealing queue, because it has weaker requirements: we can be sure that every task is removed from it at least once.

    EDIT: reactions to the questions:

    remove task by taking is OK, but remove task by pushing task in the queue!

    Sorry, that was a mistake, now fixed. It is popping or taking.

    case 3 in fib example in page 6, is it?

    Yes.

    why? I can’t understand this problem.

    The problem is, this task could be in a queue for any thread or it could be currently executing on any thread. So you would have to at the very least search through tasks that are running on each thread, using a lock for every thread. And every thread would have to use lock whenever it changed its running task. If the task isn’t currently running, you have to at least lock the queue you are removing from. Which also makes the analysis of the behavior of the queue more complicated: now things can vanish from the middle of the queue.

    what is the logical link between remove locks from pop and push, and duplicating queue?

    When you remove the locks, you can’t be completely sure that a task is removed exactly once. What could happen is that there is only one task in the queue and two different threads call take and pop at the same time. Because pop doesn’t use locks, the same task is removed twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been studying .Net threading and have learned about the Threading.Task and Threading.Task.Parallel classes.
i am self-studying asp.net and was trying some small projects to help understand the
After studying TCP/UDP difference all week, I just can't decide which to use. I
I'm currently studying indexers chapter, but I'm unable to understand this[int pos] and this[string
I'm studying java web services and trying to follow the oracle tutorial but it
when studying RMI sometimes (head first Java) dudes use Naming.rebind(name, object) but other peoples
I am studying patterns and anti-patterns. I have a clear idea about patterns, but
Studying vision, I would like to play with the Microsoft Kinect. Can I use
I began studying Java Regular Expression recently and I found some really intersting task.For
Studying compilers course, I am left wondering why use registers at all. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.