Advertisement
Guest User

Untitled

a guest
May 2nd, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.47 KB | None | 0 0
  1. let calc (func:double -> double) (l,r, step : double)  threadNumber:int =
  2.  let n = (r-l)/double threadNumber
  3.  let res =  ref 0.0
  4.  let threadArray = Array.init threadNumber ( fun x ->
  5.   new Thread(ThreadStart(fun _ ->
  6.     let threadRes = squareOnRange (func) (l+double x*n) (l+(double x+1.0)*n) step
  7.     Monitor.Enter(res)
  8.     res := !res + threadRes
  9.     Monitor.Enter(res)
  10.    )
  11.   ))
  12.  for x in threadArray do
  13.   x.Start()
  14.  for x in threadArray do
  15.   x.Join()
  16.  res.Value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement