Skip to content

Instantly share code, notes, and snippets.

@borakasmer
Last active August 18, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borakasmer/f42176a042a05ae3d715d3a591197003 to your computer and use it in GitHub Desktop.
Save borakasmer/f42176a042a05ae3d715d3a591197003 to your computer and use it in GitHub Desktop.
package main
import (
"container/list"
"fmt"
"math/rand"
"sync"
"time"
)
func makeRangeList2(min,max int) *list.List{
a := make([]int,max-min+1)
queue := list.New()
for i:= range a{
queue.PushBack(min+i)
}
return queue
}
func makeRangeList(min,max int) *list.List{
queue := list.New()
for i:= 0;i<max;i++ {
queue.PushBack(min+i)
}
return queue
}
func main() {
start := time.Now()
numberList := makeRangeList(1,10)
var wg sync.WaitGroup
wg.Add(numberList.Len())
for numberList.Len()>0{
//wg.Add(1)
e := numberList.Front()
go printNumber(e,&wg)
numberList.Remove(e)
}
wg.Wait()
/*
for numberList.Len()>0{
e := numberList.Front()
//d := time.Duration(rand.Intn(5)) * time.Second
d := time.Duration(5) * time.Second
time.Sleep(d)
fmt.Println(e.Value)
numberList.Remove(e)
}
*/
finish :=time.Now()
diff := finish.Sub(start)
fmt.Println("Geçen Toplam Süre:",diff.Milliseconds())
}
func printNumber (number *list.Element,wg *sync.WaitGroup){
//d := time.Duration(rand.Intn(5)) * time.Second
d := time.Duration(5) * time.Second
time.Sleep(d)
fmt.Println(number.Value)
wg.Done()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment