#How to block until length of array != 0?
5 messages · Page 1 of 1 (latest)
yes, the access to the array is guarded by locks, and as you already guessed another goroutine takes the lock, appends to the array and releases the lock
let's say i can also put len(arr) in a function which takes the lock, checks len, releases the lock, and returns the length
maybe after appending in the other goroutine i should write to a channel that loopedFunction listens on?
I would do this mostly
Minus the channel because channels are not fast.
Basically have a lock that starts locked (or a wait group but they are slightly more epensives than locks) have this goroutine waits on it.
And when the other goroutine modify the array length, it will do:
if len(arr) != 0 {
l.Unlock()
}