simpleman
simpleman

Reputation: 148

F# Asynch thread problem

I am learning F# and very interested in this language

I try to create async expression to run asynchronously.

for example

let prop1=async{ 
    for i=0 to 1000000 do  ()
       MessageBox.Show("Done")
    }

let prop2=async{ 
    for i=0 to 1000000 do  ()
       MessageBox.Show("Done2")
    }

Async.Start(prop1)
Async.Start(prop2)

when i run the program, i got that there are thread amount increasing of program process, from 6 to 8 , when i done close 2 message box , the process seem not destroy those created threads , the count also 8 , what happened or i got misunderstand about F# asynchronous

Thank for your help

Upvotes: 1

Views: 966

Answers (2)

Optillect Team
Optillect Team

Reputation: 1747

The runtime might use a thread pool, that is threads are not destroyed, but waiting for another asynchronous tasks. This technique helps the runtime reduce time to start a new async. operation, because creating a new thread might consume some time and resources.

Upvotes: 0

sehe
sehe

Reputation: 392863

The threads are taken from a thread pool (which is why there are more threads than actions, incidentally).

The pool exists until the application terminates.

Nothing to worry about

Edit For a nice in-depth article on F#, async and ThreadPool: http://www.voyce.com/index.php/2011/05/27/fsharp-async-plays-well-with-others/

Upvotes: 2

Related Questions