I recently found that in Qt,  reference counting to guard a resource, is using
ref() / deref()

But ref() is using memory_order_seq_cst
while memory_order_relaxed, should be sufficient

What is important is to guarantee that destruction is not subject to a race 
condition, to prevent double
destruction. Hence deref() with memory_order_seq_cst is enough to guarantee
that.

It does not matter how much the counter increase, but what is important
is to control how it is decreased. Hence deref(with memory_order_seq_cst)
is just enough.

I have verified the implementaiton of reference counting for shared_ptr
in clang, and it does what I describe above
(it even just use memory_order_acq_rel to decrement, and not 
memory_order_seq_cst)

https://github.com/llvm-mirror/libcxx/blob/master/include/memory#L3344

Is there a reason why Qt is not optimized in the same way? (since ref() is
used a lot, and atomic operations are a bit expensive).

Is there a requirement at some stage that the reference counter must be
ordered for increments?

Philippe

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to