The code below implements a simple timer loop that doubles the amount of 
time it waits (up to a max) after each firing. It works fine on my x86 
linux box, but behaves erratically on a Raspberry Pi ARM platform (and on 
the playground).

I'm assuming I'm doing something bad, but it isn't clear at all to me what 
I'm missing.

Code on playground and below, as well as machine specs and output. What is 
going on?

// https://play.golang.org/p/8hN9pR6LlU
package main

import (
    "fmt"
    "time"
)

func main() {
    scale := 2
    max := 15 * time.Second
    currDur := 250 * time.Millisecond

    tick := time.After(currDur)

    prev := time.Now()
    for i := 1; i <= 10; i++ {
        select {
        case t := <-tick:
            now := time.Now()
            delta := now.Sub(prev)
            prev = now
            fmt.Printf("%2d: %s %s\n", i, delta, t)
            currDur = time.Duration(int(currDur) * scale)
            if currDur >= max {
                currDur = max
            }

            tick = time.After(currDur)
        }
    }

    return
}

/*

--------------------
Host for cross compile

mke% go version
go version go1.7.3 linux/amd64

mke% lsb_release -a
No LSB modules are available.
Distributor ID:Ubuntu
Description:Ubuntu 14.04.5 LTS
Release:14.04
Codename:trusty

mke% uname -a
Linux mke 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 
2016 \
x86_64 x86_64 x86_64 GNU/Linux

# compile native
mke% go build tryit.go

# cross-compile
mke% GOOS=linux GOARCH=arm go build tryit.go

mke% ./tryit
 1: 250.192493ms 2017-01-11 14:07:12.041348721 -0500 EST
 2: 500.386557ms 2017-01-11 14:07:12.541735315 -0500 EST
 3: 1.000226231s 2017-01-11 14:07:13.541964105 -0500 EST
 4: 2.000227623s 2017-01-11 14:07:15.542191833 -0500 EST
 5: 4.000226419s 2017-01-11 14:07:19.542417936 -0500 EST
 6: 8.000232073s 2017-01-11 14:07:27.542649813 -0500 EST
 7: 15.000257032s 2017-01-11 14:07:42.542907276 -0500 EST
 8: 15.000299935s 2017-01-11 14:07:57.543207607 -0500 EST
 9: 15.000226352s 2017-01-11 14:08:12.543433699 -0500 EST
10: 15.000233635s 2017-01-11 14:08:27.543667311 -0500 EST

--------------------
Target machine (Raspberry Pi 3 B)

pi3% lsb_release -a
No LSB modules are available.
Distributor ID:Raspbian
Description:Raspbian GNU/Linux 8.0 (jessie)
Release:8.0
Codename:jessie

pi3% uname -a
Linux art-pi3 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l 
GNU/Linux

pi3% ./tryit
 1: 250.18908ms 2017-01-11 14:22:36.294351503 -0500 EST
 2: 501.487843ms 2017-01-11 14:22:36.795825492 -0500 EST
 3: 1.000988352s 2017-01-11 14:22:37.796819 -0500 EST
 4: 2.000598851s 2017-01-11 14:22:39.79741155 -0500 EST
 5: 440.832us 2017-01-11 14:22:39.797884724 -0500 EST
 6: 292.394us 2017-01-11 14:22:39.798177848 -0500 EST
 7: 266.196us 2017-01-11 14:22:39.798443888 -0500 EST
 8: 1.935652004s 2017-01-11 14:22:41.734063912 -0500 EST
 9: 458.539us 2017-01-11 14:22:41.734553753 -0500 EST
10: 267.29us 2017-01-11 14:22:41.734821408 -0500 EST

*/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to