Re: [boost] Enhanced call_once()
by Andrew J Bromage other posts by this author
Aug 7 2002 11:54PM messages near this date
Re: [boost] Enhanced call_once()
|
Re: [boost] Enhanced call_once()
G'day all.
On Wed, Aug 07, 2002 at 01:44:02PM +0300, Peter Dimov wrote:
> Are you sure that you want that.
Well, anything which has equivalent semantics and more importantly,
equivalent contention-avoidance would do. For example, a "one shot
mutex" which only succeeded in locking the first time you tried it
would do the trick, though this would probably have different
exception semantics.
> Your "once" object is dynamically initialized. It is pretty much the same as
> a boost::mutex; there is no reason for it to be more efficient than a mutex.
The same argument could be made against lightweight mutexes, or atomic
counters. Admittedly boost doesn't currently expose atomic_count as
a supported interface (arguably a good thing), but still, it's there
for a reason.
On all platforms that I'm aware of, releasing a mutex lock costs at
least one system call. On many platforms, even obtaining an
uncontested lock costs a system call. This is a heavyweight
solution for a lightweight problem: protecting a read of a single flag
which is only going to be mutated once in its lifetime. I can see
this causing problems in times of heavy concurrency.
Incidentally, I do have no problem to falling back to a single
boost::mutex in platforms where there's no better way.
Cheers,
Andrew Bromage
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Andrew J Bromage
Peter Dimov
Andrew J Bromage
William E. Kempf
Andrew J Bromage
William E. Kempf
Alexander Terekhov
Pete Becker
Andrew J Bromage
Peter Dimov
Andrew J Bromage
William E. Kempf
Andrew J Bromage
William E. Kempf
Rene Rivera
William E. Kempf
Andrew J Bromage
Jason Stewart
Andrew J Bromage
Andrew J Bromage
Rob Stewart
William E. Kempf
William E. Kempf
Alexander Terekhov
Peter Dimov
Peter Dimov
Pete Becker
William E. Kempf
William E. Kempf
Pete Becker
|