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 3609732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:39:54+00:00 2026-05-18T21:39:54+00:00

In goofing around with some F# (via MonoDevelop), I have written a routine which

  • 0

In goofing around with some F# (via MonoDevelop), I have written a routine which lists files in a directory with one thread:

let rec loop (path:string) = 
  Array.append
    (
        path |> Directory.GetFiles
    )
    (
        path 
        |> Directory.GetDirectories
        |> Array.map loop
        |> Array.concat
    )

And then an asynchronous version of it:

let rec loopPar (path:string) = 
  Array.append
    ( 
        path |> Directory.GetFiles
    )
    ( 
        let paths = path |> Directory.GetDirectories
        if paths <> [||] then
            [| for p in paths -> async { return (loopPar p) } |]
            |> Async.Parallel
            |> Async.RunSynchronously 
            |> Array.concat
        else 
            [||]
    ) 

On small directories, the asynchronous version works fine. On bigger directories (e.g. many thousands of directories and files), the asynchronous version seems to hang. What am I missing?

I know that creating thousands of threads is never going to be the most efficient solution — I only have 8 CPUs — but I am baffled that for larger directories the asynchronous function just doesn’t respond (even after a half hour). It doesn’t visibly fail, though, which baffles me. Is there a thread pool which is exhausted?

How do these threads actually work?

Edit:

According to this document:

Mono >=2.8.x has a new threadpool that is much, much harder to deadlock. If you get a threadpool deadlock chances are that your program is trying to be deadlocked.

😀

  • 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-18T21:39:55+00:00Added an answer on May 18, 2026 at 9:39 pm

    Yes, most likely you are overwhelming the Mono thread pool which is grinding your system’s performance to a halt.

    If you remember one thing from this, it is that threads are expensive. Each thread needs its own stack (megabytes in size) and slice of CPU time (requiring context switching). Because of this, it is rarely a good idea to spin up your own thread for short lived tasks. That is why .NET has a ThreadPool.

    A ThreadPool is an existing collection of threads for short tasks, and it is what F# users for its Async workflows. Whenever you do run an F# Async operation, it simply delegates the action to the thread pool.

    The problem is, what happens when you spawn thousands of asynchronous actions in F# all at once? A naive implementation would simply spawn as many threads as needed. However, if you need 1,000 threads that means you need 1,000 x 4MB of stack space. Even if you had enough memory for all the stacks, your CPU would constantly be switching between the different threads. (And paging the local stacks in and out of memory.)

    IIRC, the Windows .NET implementation was smart enough not to spawn a ton of threads and simply queue the work up until there were some spare threads to perform the actions. In other words, it would keep adding threads until it had a fixed number and just use those. However, I don’t know how Mono’s thread pool is implemented.

    tl;dr: This is working as expected.

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

Sidebar

Related Questions

I have the following code which does nothing but reading some values from a
Complete noob to C , just getting started with some goofing around, wondering how
I'm goofing around with the new youtube as3 API but got stuck. This is
Im goofing around with XNA and I've come to the part where I need
I am goofing around with pointers and structures. I want to achieve the following:
There is a similar question going around, but it just got the same old
I have an odd sorting case I'm struggling to work out using LINQs GroupBy
I have a sample query as shown below: SELECT * FROM [#temp1] UNION SELECT
I want to do some basic filtering on a file. Read it, do processing,
I have googing,and it does not work. This is my log4j.properties: # stdout 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.