LEFT | RIGHT |
(no file at all) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 // This program prints to stdout from multiple goroutines multiplexed onto |
| 6 // multiple threads. It is used as the tracee program by the debugger (tracer) |
| 7 // program in the parent directory. |
| 8 package main |
| 9 |
| 10 import ( |
| 11 "fmt" |
| 12 "runtime" |
| 13 "syscall" |
| 14 "time" |
| 15 ) |
| 16 |
| 17 // ansiColor is whether to display ANSI color codes in the program's output. |
| 18 // This distinguishes this program's output (the tracee's) from the debugger |
| 19 // program's output (the tracer's). |
| 20 const ansiColor = false |
| 21 |
| 22 var prefix, suffix string |
| 23 |
| 24 func run(base int, sleep time.Duration, lockOSThread bool) { |
| 25 if lockOSThread { |
| 26 runtime.LockOSThread() |
| 27 } |
| 28 for i := 0; ; i++ { |
| 29 fmt.Printf("%sx=%5d tid=%d%s\n", prefix, base+i, syscall.Gettid(
), suffix) |
| 30 time.Sleep(sleep) |
| 31 } |
| 32 } |
| 33 |
| 34 func main() { |
| 35 if ansiColor { |
| 36 prefix, suffix = "\x1b[36m", "\x1b[0m" |
| 37 } |
| 38 go run(0, 300*time.Millisecond, false) |
| 39 go run(100, 500*time.Millisecond, false) |
| 40 go run(10000, 700*time.Millisecond, true) |
| 41 time.Sleep(5 * time.Second) |
| 42 } |
LEFT | RIGHT |