Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I think that simply moving line 58 to between 61,62 would fix this.

Doing that would erase the whole benefit of allocating a static array in the first place (you really don't want to be allocating memory for every packet that comes through). The funny thing is the author correctly handles this type of synchronization problem elsewhere, see lines 97-100. The right thing to do is to wait for acknowledgement from both loggers before reusing shared memory, but that sort of defeats his broader argument: if you are explicitly guarding every shared memory access with a barrier, then you might as well have been using any shared memory language besides Go. Buffered channels in both directions used to implement barriers are every bit as error-prone and complex as using a reader-writer lock explicitly.



> Doing that would erase the whole benefit of allocating a static array in the first place (you really don't want to be allocating memory for every packet that comes through).

The benefit is dubious. Performance is unlikely to be important in a single-connection logger. My advice is to lean on the garbage collector. Allocate away.

Buffered channels are certainly more complex, but if you're never sharing memory, shouldn't hurt you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: