@Dave Cheney: I want to avoid a *global* mutex, because my function can 
write to different files.

@Konstantin Khomoutov: You are right, I could use a map of mutexes.
As Alex Bligh said, I also need to add a mutex on this map, which is a bit 
complicated...

I'm not using concurrency to write faster.
I have several goroutines (started by HTTP request) that append strings to 
the same file.

@Konstantin Khomoutov + @Alex Bligh: I like this idea about using a channel 
+ goroutine for each file.
It would also help me to not open/close file for each write.

My real question is: is there a problem in the *writeBuffer()* function ?
It is very simple, and it looks that it works.

Le mardi 5 juillet 2016 13:46:38 UTC+2, Alex Bligh a écrit :
>
>
> > On 5 Jul 2016, at 10:38, Pierre Durand <pierre...@gmail.com 
> <javascript:>> wrote: 
> > 
> > So, I've written writeMutex(), that uses a mutex. 
> > It works as expected, but in my real code, I'd prefer to avoid mutex. 
> > (in my real code write() can write to different files; the file's name 
> is given as argument) 
>
> ... or more idiomatically, set up a channel per file you are writing, make 
> write() write to that channel, and have a writer go-routine which reads 
> from that channel and writes to the file itself. 
>
> -- 
> Alex Bligh 
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to