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

  • SEARCH
  • Home
  • 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 9065539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:31:34+00:00 2026-06-16T16:31:34+00:00

I have a general question about threads (or fibers) on Windows and Linux, in

  • 0

I have a general question about threads (or fibers) on Windows and Linux, in any programming language:

Is it possible to have a “2nd thread standing by” and have it quickly jump into action and help with a small task for a few milliseconds, without getting pre-empted?
I should add that I am hoping for legible code without mutexes and spin locks.

To show that conventional thread pools do not work for small tasks, consider a matrix inversion problem in C#.
I am using Ivan Kuckir’s matrix class.
I copy his Invert function and call it InvertParallel as follows:

public Matrix InvertParallel()   // modified from Ivan's Invert(), see link above
{
    if (L == null) MakeLU();
    Matrix inv = new Matrix(rows, cols);
    Parallel.ForEach<int>(Enumerable.Range(0, rows), rowID =>
    {
        Matrix Ei = Matrix.ZeroMatrix(rows, 1);
        Ei[rowID, 0] = 1;
        Matrix col = SolveWith(Ei);
        inv.SetCol(col, rowID);
    });
    return inv;
}

Then I invoke both Invert and Invert_Parallel functions and measure time it takes:

static void Main()
{
    Stopwatch sw = new Stopwatch(); sw.Start();
    Matrix A = Matrix.IdentityMatrix(50, 50);
    Matrix I1 = A.Invert();
    long elapsed1 = sw.ElapsedMilliseconds;
    Matrix I2 = A.InvertParallel();
    long elapsed2 = sw.ElapsedMilliseconds - elapsed1;
    Console.WriteLine("Matrix size=" + A.rows + ", Invert=" + elapsed1 + "ms, Invert_Parallel=" + elapsed2 + "ms");
}

The fairly obvious results show that for small tasks (matrix size 50), launching tasks from a thread pool is slower than running single-threaded:

Matrix size=50,  Invert=  5ms,  InvertParallel=21ms
Matrix size=100, Invert= 19ms,  InvertParallel=24ms
Matrix size=200, Invert=137ms,  InvertParallel=44ms

(Apologies – I had to remove all links from the notes below, as I am a new poster)

P.S. possibly related S/O articles: ‘how to start two threads at the same time’, ‘Linux – threads and process scheduling priorities’

P.S. Yes I know there is a more clever algorithm for calculating the inverse, which scales as O(N^2.376).

P.P.S. I am not familiar with User-Mode Scheduling (UMS on Windows) User-Mode Scheduling (‘UMS’ on Windows), can it help?

  • 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-06-16T16:31:36+00:00Added an answer on June 16, 2026 at 4:31 pm

    Passing tasks between threads, especially those which have a significant amount of data associated with them has a non-trivial overhead which can result in slower performance for small tasks as you have seen. You need to find the sweet spot where using more than one core is faster.

    BTW you can get a small improvement by making one of the worker threads, the current thread saving one context switch and copies between caches. e.g. if you have 8 cores, pass 1/7 to 7 other threads and do 1/8 in the current thread.

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

Sidebar

Related Questions

I have a general question about interpreters of functional languages: Are there actually any
I have a question about the Microsoft PPL library, and parallel programming in general.
I have general question about Linux. Will the inode be created if I create
I have a general question about a threads and callbacks. Say for example we
I have a general question about the new Django 1.3 static file framework. I
I have a general question about the way that database indexing works, particularly in
i have a general question about how sql server evaluates the joins.The query is
i have a general question about properties and ivars. ive seen many different examples
I have a general question for the group. I am about to start a
I have a general question about System.Threading.Threadpool when run in a webapplication on IIS.

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.