Giter Site home page Giter Site logo

Comments (2)

ankisme avatar ankisme commented on August 25, 2024

The way I use it cause data race.

=== RUN   TestGoDisruptorMultipleProducer
==================
WARNING: DATA RACE
Read at 0x00c000070560 by goroutine 9:
  github.com/smartystreets-prototypes/go-disruptor.(*DefaultWriter).Reserve()
      D:/proj/mine/gopath/pkg/mod/github.com/smartystreets-prototypes/[email protected]/default_writer.go:28 +0x5c
  web/business/taskqueuepackage/test_test.publish()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:29 +0xc6

Previous write at 0x00c000070560 by goroutine 8:
  github.com/smartystreets-prototypes/go-disruptor.(*DefaultWriter).Reserve()
      D:/proj/mine/gopath/pkg/mod/github.com/smartystreets-prototypes/[email protected]/default_writer.go:28 +0x78
  web/business/taskqueuepackage/test_test.publish()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:29 +0xc6

Goroutine 9 (running) created at:
  web/business/taskqueuepackage/test_test.TestGoDisruptorMultipleProducer()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:21 +0x18c
  testing.tRunner()
      D:/go/src/testing/testing.go:909 +0x1a0

Goroutine 8 (running) created at:
  web/business/taskqueuepackage/test_test.TestGoDisruptorMultipleProducer()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:21 +0x18c
  testing.tRunner()
      D:/go/src/testing/testing.go:909 +0x1a0
==================
==================
WARNING: DATA RACE
Read at 0x00c000070568 by goroutine 9:
  github.com/smartystreets-prototypes/go-disruptor.(*DefaultWriter).Reserve()
      D:/proj/mine/gopath/pkg/mod/github.com/smartystreets-prototypes/[email protected]/default_writer.go:29 +0x137
  web/business/taskqueuepackage/test_test.publish()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:29 +0xc6

Previous write at 0x00c000070568 by goroutine 8:
  github.com/smartystreets-prototypes/go-disruptor.(*DefaultWriter).Reserve()
      D:/proj/mine/gopath/pkg/mod/github.com/smartystreets-prototypes/[email protected]/default_writer.go:34 +0xce
  web/business/taskqueuepackage/test_test.publish()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:29 +0xc6

Goroutine 9 (running) created at:
  web/business/taskqueuepackage/test_test.TestGoDisruptorMultipleProducer()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:21 +0x18c
  testing.tRunner()
      D:/go/src/testing/testing.go:909 +0x1a0

Goroutine 8 (running) created at:
  web/business/taskqueuepackage/test_test.TestGoDisruptorMultipleProducer()
      D:/proj/mine/gopath/src/gitee-server/business/taskqueuepackage/test/GoDisruptorMultipleProducer_test.go:21 +0x18c
  testing.tRunner()
      D:/go/src/testing/testing.go:909 +0x1a0

And the DefaultWriter seems should be used in only a goroutine?

func (this *DefaultWriter) Reserve(count int64) int64 {
	if count <= 0 {
		panic(ErrMinimumReservationSize)
	}

	this.previous += count
	for spin := int64(0); this.previous-this.capacity > this.gate; spin++ {
		if spin&SpinMask == 0 {
			runtime.Gosched() // LockSupport.parkNanos(1L); http://bit.ly/1xiDINZ
		}

		this.gate = this.upstream.Load()
	}
	return this.previous
}

from go-disruptor.

joliver avatar joliver commented on August 25, 2024

Right now it only supports a single producer.

If you want to do multiple producers, the only workaround is to do:

mutex.Lock()
// claim
// write
mutex.Unlock()

from go-disruptor.

Related Issues (11)

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.