Git Product home page Git Product logo

fqueue's People

Contributors

templexxx avatar

Stargazers

 avatar  avatar

Watchers

 avatar

fqueue's Issues

这代码有 race 啊

不知道为啥要在汇编代码前面加 // build !race

去了之后写了个俩消费者俩生产者的 demo,然后 go run -race demo.go 跑了一下就 race 了。

看到你给 go 提的 xor 的 issue 追过来的,想顺便问一下你提到的 intel 汇编的那个指令编程优化手册是在哪找到的,能否发个链接?

demo.go:

package main

import (
    "sync"
    "github.com/templexxx/fqueue"
)

func main() {
    q, err := fqueue.New(16)
    if err != nil {
        panic(err)
    }
    var w sync.WaitGroup
    w.Add(4)
    go func() {
        defer w.Done()
        for i := 0; i < 10000; i++ {
            q.Push(i)
        }
    }()
    go func() {
        defer w.Done()
        for i := 10000; i < 20000; i++ {
            q.Push(i)
        }
    }()
    go func() {
        defer w.Done()
        for i := 0; i < 10000; i++ {
            q.Get()
        }
    }()
    go func() {
        defer w.Done()
        for i := 10000; i < 20000; i++ {
            q.Get()
        }
    }()
    w.Wait()
}
==================
WARNING: DATA RACE
Read at 0x00c42007c028 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c42007c028 by goroutine 5:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8
  main.main.func1()
      /home/cholerae/test/gotest/testfqueue.go:18 +0x9e

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007c040 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c42007c040 by goroutine 5:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8
  main.main.func1()
      /home/cholerae/test/gotest/testfqueue.go:18 +0x9e

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007c030 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c42007c030 by goroutine 5:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e
  main.main.func1()
      /home/cholerae/test/gotest/testfqueue.go:18 +0x9e

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007c018 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c42007c018 by goroutine 5:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e
  main.main.func1()
      /home/cholerae/test/gotest/testfqueue.go:18 +0x9e

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007d1d0 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c42007d1d0 by goroutine 5:
  [failed to restore the stack]

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007d1f8 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c42007d1f8 by goroutine 5:
  [failed to restore the stack]

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007d210 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c42007d210 by goroutine 5:
  [failed to restore the stack]

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c42007d1e8 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c42007d1e8 by goroutine 5:
  [failed to restore the stack]

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 5 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:15 +0x168
==================
==================
WARNING: DATA RACE
Read at 0x00c4200b9738 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c4200b9738 by goroutine 6:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8
  main.main.func2()
      /home/cholerae/test/gotest/testfqueue.go:24 +0xa1

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 6 (finished) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:21 +0x194
==================
==================
WARNING: DATA RACE
Read at 0x00c4200b9750 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:111 +0x15e
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c4200b9750 by goroutine 6:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:77 +0x1b8
  main.main.func2()
      /home/cholerae/test/gotest/testfqueue.go:24 +0xa1

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 6 (finished) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:21 +0x194
==================
==================
WARNING: DATA RACE
Read at 0x00c4200b9728 by goroutine 7:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func3()
      /home/cholerae/test/gotest/testfqueue.go:30 +0x6b

Previous write at 0x00c4200b9728 by goroutine 6:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e
  main.main.func2()
      /home/cholerae/test/gotest/testfqueue.go:24 +0xa1

Goroutine 7 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:27 +0x1c0

Goroutine 6 (finished) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:21 +0x194
==================
==================
WARNING: DATA RACE
Read at 0x00c4200b9740 by goroutine 8:
  github.com/templexxx/fqueue.(*queue).Get()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:112 +0x196
  main.main.func4()
      /home/cholerae/test/gotest/testfqueue.go:36 +0x6e

Previous write at 0x00c4200b9740 by goroutine 6:
  github.com/templexxx/fqueue.(*queue).Push()
      /home/cholerae/gopath/src/github.com/templexxx/fqueue/fqueue.go:76 +0x17e
  main.main.func2()
      /home/cholerae/test/gotest/testfqueue.go:24 +0xa1

Goroutine 8 (running) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:33 +0x1ec

Goroutine 6 (finished) created at:
  main.main()
      /home/cholerae/test/gotest/testfqueue.go:21 +0x194
==================
Found 12 data race(s)
exit status 66

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.