Re:Common Pitfalls in Writing Lock-Free Algorithms
by Afforess on Wednesday March 27, 2013 @08:47PM
(#5452825)
I found the observation about new/delete not being necessarily safe interesting. Been writing Java too long, Java has no delete (garbage collection) and presumably new would have been creating a linked list entry object, which is safe.
[ Parent
| on HN ]
Re:Common Pitfalls in Writing Lock-Free Algorithms
by swift on Thursday March 28, 2013 @12:31PM
(#5455836)
This is actually a really good point. Garbage collection has significant advantages for concurrency because it solves this problem so nicely; avoiding these issues in C++ often isn't just difficult for the programmer but also costs you performance. (Of course, if you generate so much garbage that the GC is running all the time, it will become a bottleneck, but the same is true of excessive allocation and deallocation even in unmanaged languages.)
Re:Common Pitfalls in Writing Lock-Free Algorithms
by taeric on Wednesday March 27, 2013 @10:08PM
(#5453054)
But could cause a garbage collection cycle, right? If so, I think this still counts in the "not safe" category.
Re:Common Pitfalls in Writing Lock-Free Algorithms
by swift on Thursday March 28, 2013 @12:26PM
(#5455801)
Generally garbage collection algorithms more sophisticated than reference counting can handle cycles just fine. Certainly this is the case for Java.
Edit: Or perhaps you mean, could cause the garbage collector to run? I don't see why that'd be an issue either.
Re:Common Pitfalls in Writing Lock-Free Algorithms
by taeric on Friday March 29, 2013 @09:34AM
(#5460600)
That is what I meant. And having a garbage collector run could potentially freeze the JVM, causing a performance hit. (I mean, it is basically a global lock on the entire system, right?)
Basically, my reading of "safe" meant "would not block." A garbage collection cycle stops everything, so is effectively a block, right?
Re:Common Pitfalls in Writing Lock-Free Algorithms
by swift on Friday March 29, 2013 @04:56PM
(#5463001)
I read "safe" differently than you did; now I'm on the same page. With or without a GC, if you want to guarantee safety in that sense no matter what, you're right - you just can't allocate memory. So in the worst case running in a managed environment doesn't buy you much, but often the guarantees you need are a bit looser than that, and in that case managed memory can be really beneficial.