On Fri, Dec 14, 2012 at 12:33 PM, Joshua Cranmer <pidgeo...@verizon.net>wrote:

> 3. Similar to #2, the ideal version of a reference counter would be
> mozilla::Atomic<nsrefcnt, mozilla::Unordered> (which would make threadsafe
> refcounting cheaper on our ARM platforms if we compiled with gcc 4.6 or
> clang 3.1 or newer). However, I'm not sure that no one has written code
> that relies on atomic operations having memory ordering properties, and I
> don't want to go through and audit every thread-safe XPCOM class.
>

Is code like this safe in the C++1 Unordered model?
Thread 1:
  int x = obj->v;
  obj->Release();
Thread 2:
  obj->Release();
where obj's destructor trashes obj->v.
The potential hazard is if thread 1's obj->Release() atomic decrement is
reordered to run before the obj->v load has completed, then Thread 2's
obj->Release() runs and trashes obj->v, and thread 1 reads the trashed
value.

For what it's worth, I think asking programmers to even think about such
question is insane, so I'd go for full memory barriers and sequential
consistency until we have benchmark numbers showing big wins from other
choices.

Rob
-- 
Jesus called them together and said, “You know that the rulers of the
Gentiles lord it over them, and their high officials exercise authority
over them. Not so with you. Instead, whoever wants to become great among
you must be your servant, and whoever wants to be first must be your
slave — just
as the Son of Man did not come to be served, but to serve, and to give his
life as a ransom for many.” [Matthew 20:25-28]
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to