On 05/19/2014 08:41 AM, Steve Wampler wrote:
>       procedure main()
>           L2 := mutex([])
>           L1 := []
>           every 1 to 3 do put(L1, thread (put(L2, 1 to 5),delay(?200)))
>           every wait(!L1)
>           every writes(" "||!L2 | "\n")
>       end
>
> The delay is in there because the simple gen() [1 to 5] I used is so
> fast that without the delay each thread completes before the next
> gets created and run!

You can *almost* get rid of the delay by using create and spawn() instead
of thread, but a simple gen() is still more often than not able to complete
before the next thread gets spawned.

For example, the following version:

     procedure main()
         L2 := mutex([])
         L0 := [: |(create put(L2,1 to 5))\3 :]
         every put(L1 := [], spawn(!L0))
         every wait(!L1)
         every writes(" "||!L2 | "\n")
     end

Nearly always produces:
-----------------------------------
->s
  1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
->s
  1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
->s
  1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
----------------------------------
and only occasionally produces a different order:
----------------------------------
->s
  1 1 2 3 2 4 3 5 4 5 1 2 3 4 5
->
----------------------------------

So any real randomization would have to come from inside gen() and not
solely from the parallelization.

-- 
Steve Wampler -- [email protected]
The gods that smiled on your birth are now laughing out loud.

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to