1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 // mysleep returns the absolute start time in ms.
9 long long mysleep(int seconds);
11 // twoSleep returns the absolute start time of the first sleep
13 long long twoSleep(int);
22 var sleepDone
= make(chan int64)
24 // parallelSleep returns the absolute difference between the start time
26 func parallelSleep(n
int) int64 {
27 t
:= int64(C
.twoSleep(C
.int(n
))) - <-sleepDone
34 //export BackgroundSleep
35 func BackgroundSleep(n
int32) {
37 sleepDone
<- int64(C
.mysleep(C
.int(n
)))
41 func testParallelSleep(t
*testing
.T
) {
43 dt
:= time
.Duration(parallelSleep(sleepSec
)) * time
.Millisecond
44 t
.Logf("difference in start time for two sleep(%d) is %v", sleepSec
, dt
)
45 // bug used to run sleeps in serial, producing a 2*sleepSec-second delay.
46 // we detect if the start times of those sleeps are > 0.5*sleepSec-second.
47 if dt
>= time
.Duration(sleepSec
)*time
.Second
/2 {
48 t
.Fatalf("parallel %d-second sleeps slept for %f seconds", sleepSec
, dt
.Seconds())