I have the following dummy code for testing TPL in F #. (Mono 4.5, Xamarin Studio, Quad-Core MacBook Pro)
To my surprise, all processes run in a single thread. No parallelism at all.
open System
open System.Threading
open System.Threading.Tasks
let doWork (num:int) (taskId:int) : unit =
for i in 1 .. num do
Thread.Sleep(10)
for j in 1 .. 1000 do
()
Console.WriteLine(String.Format("Task {0} loop: {1}, thread id {2}", taskId, i, Thread.CurrentThread.ManagedThreadId))
[<EntryPoint>]
let main argv =
let t2 = Task.Factory.StartNew(fun() -> doWork 10 2)
Console.WriteLine("launched t2")
let t1 = Task.Factory.StartNew(fun() -> doWork 8 1)
Console.WriteLine("launched t1")
let t3 = Task.Factory.StartNew(fun() -> doWork 10 3)
Console.WriteLine("launched t3")
let t4 = Task.Factory.StartNew(fun() -> doWork 5 4)
Console.WriteLine("launched t4")
Task.WaitAll(t1,t2,t3,t4)
0
However, if I increase the disconnect time of the stream from 10 to 100 ms, I can see a bit of parallelism.
How am I wrong? What does it mean? I considered the possibility that the CPU shut down before TPL could start the task in a new thread. But for me it does not make sense. I can increase the internal dummy loop for j in 1 .. 1000 do ()to over 1000 cycles. The result is the same: no parallelism ( thread.sleep10 ms set).
#, , : ( )
:
, , "" ,
2:
Luaan, . parallelism ( ). , - . Luaan , TPL ? , , TPL ?
3:
@FyodorSoikin , . , - Mono TPL . Mono TPL - 20 . , Mono , ( ) Mono Windows.