Skip to content

Commit 679d332

Browse files
committed
no need to caste to time.Duration
1 parent d4febc5 commit 679d332

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

day07-goroutines-channels-1/race.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func incr(s string) {
3131
for i := 0; i < 50; i++ {
3232
x:=globalcounter
3333
x++
34-
time.Sleep(time.Duration(rand.Intn(2))*time.Millisecond)
34+
time.Sleep(rand.Intn(2)*time.Millisecond) //OR runtime.Gosched() //Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, so execution resumes automatically.
3535
globalcounter = x
3636
fmt.Println(s, i, "counter:", globalcounter)
3737
}

day11-mutex-events-models-5/atomic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
func incrementor(s string) {
2929
for i := 0; i < 10000; i++ {
3030
runtime.Gosched() //Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, so execution resumes automatically.
31-
//Alternative to Gosched() is //time.Sleep(time.Duration(rand.Intn(2))*time.Millisecond)
31+
//Alternative to Gosched() is //time.Sleep(rand.Intn(2)*time.Millisecond)
3232

3333
atomic.AddInt64(&count, 1)
3434
//count++

0 commit comments

Comments
 (0)