On 25 Sep 2014 18:57, "Sankar P" <sankar.c...@gmail.com> wrote:
>
> 2014-09-25 14:05 GMT+05:30 Dave Cheney <da...@cheney.net>:
> > What happens to the data that these goroutines are writing ? You don't seem
> > to be concerned with entries being ordered in this shared buffer so why not
> > have each goroutine collect its own buffer then transmit it via a channel
> > when it is done?
>
> Actually each go routine will have only one value to append to the
> buffer. I have a WaitGroup where I will wait until all the goroutines
> have returned and then I will access the contents of the common
> buffer. And as you said, the ordering of the elements in the buffer
> does not matter to me.
>
> I was trying to avoid using mutexes or channels as I felt it may be
> costly.
Please, please. Write your code _then_ benchmark it if you think it is too slow.
If you do things the other way around, you'll get the wrong result.
2014-09-25 14:05 GMT+05:30 Dave Cheney <da...@cheney.net>:
> What happens to the data that these goroutines are writing ? You don't seem
> to be concerned with entries being ordered in this shared buffer so why not
> have each goroutine collect its own buffer then transmit it via a channel
> when it is done?
Actually each go routine will have only one value to append to the
buffer. I have a WaitGroup where I will wait until all the goroutines
have returned and then I will access the contents of the common
buffer. And as you said, the ordering of the elements in the buffer
does not matter to me.
I was trying to avoid using mutexes or channels as I felt it may be
costly. I was looking for some lock-free datastructure (if any) which
might internally work with some kind of byte-range locks over a
pre-allocated buffer to give an illusion of lock-free-thread-safe
arrays which has only an append operation.
But I will probably leave that experiment later for some free time
hacking and will use mutexes properly for now, remembering Rob Pike's
advice to not use fancy algorithms/datastructures and measure things
before optimizing :)
2014-09-25 14:05 GMT+05:30 Dave Cheney <da...@cheney.net>:
> What happens to the data that these goroutines are writing ? You don't seem
> to be concerned with entries being ordered in this shared buffer so why not
> have each goroutine collect its own buffer then transmit it via a channel
> when it is done?
Actually each go routine will have only one value to append to the
buffer. I have a WaitGroup where I will wait until all the goroutines
have returned and then I will access the contents of the common
buffer. And as you said, the ordering of the elements in the buffer
does not matter to me.
I was trying to avoid using mutexes or channels as I felt it may be
costly. I was looking for some lock-free datastructure (if any) which
might internally work with some kind of byte-range locks over a
pre-allocated buffer to give an illusion of lock-free-thread-safe
arrays which has only an append operation.
But I will probably leave that experiment later for some free time
hacking and will use mutexes properly for now, remembering Rob Pike's
advice to not use fancy algorithms/datastructures and measure things
before optimizing :)
Thanks.
I was trying to avoid using mutexes or channels as I felt it may be
costly. I was looking for some lock-free datastructure (if any) which
might internally work with some kind of byte-range locks over a
pre-allocated buffer to give an illusion of lock-free-thread-safe
arrays which has only an append operation.