Skip to content

Unexpected TaskBuilder behaviour #23

@polytypic

Description

@polytypic

Here is a simple program using TaskBuilder:

open System.Threading
open System.Threading.Tasks
open ExtCore.Control.Tasks

[<EntryPoint>]
let main _ =
  let completed = ref false
  let t = tasks {
    printfn "Started"
    let n = ref 10
    let s = ref 0
    printfn "Next while"
    while 0 < !n do
      printfn "Iteration"
      s := !n + !s
      n := !n - 1
    printfn "Sum %A" !s
    lock completed <| fun () ->
      completed := true
      Monitor.PulseAll completed
  }
  t.Start ()
  lock completed <| fun () ->
    while not !completed do
      Monitor.Wait completed |> ignore
  0

Running this program (Mono, but I don't expect different behavior under .Net) I get the following output:

Started
Next while

After which nothing happens. I would expect the computation to run to completion. Like when happens if you replace tasks with async and t.Start () with Async.Start t.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions