The Barrier function simply does Done() then Wait()
What I want is that each worker does a two-phase operation
- wait until everybody has passed a start barrier
- do some work
- wait until everybody has passed an end barrier
- do some work
.. doing this some number of times
In parallel, main has created and initialised the start and end waitgroups wgstart and wgend
main has then created the worker goroutines (in the real thing I want roughly one worker per core, so there’s also some setting of GOMAXPROCS)
main then enters a loop in which it
- waits until everbody including it has passed the start barrier
- resets the start barrier
- waits until everybody has bassed the end barrier
- resets the end barrier
This behaviour is observed, except the code panics, both in the playgorund and on my machine. Typical failure is:
----------- [2] main about to barrier start ---------------
w[7] enters barrier startpanic: sync: WaitGroup is reused before previous Wait has returned
goroutine 10 [running]:
sync.(*WaitGroup).Wait(0xc00002c030)
/usr/local/go-faketime/src/sync/waitgroup.go:132 +0xae
main.Barrier(0x4, 0x4bef21, 0x3, 0xc00002c030)
/tmp/sandbox686473236/prog.go:51 +0x12b
main.worker(0x4, 0xc00002c020, 0xc00002c030, 0xa)
/tmp/sandbox686473236/prog.go:35 +0x309
created by main.main
/tmp/sandbox686473236/prog.go:78 +0x295
What have I misunderstood and done wrongly?
Thanks!
— P
WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message. If you have received this communication in error, please notify the sender and destroy and delete any copies you may have received.
http://www.bsc.es/disclaimer