Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > Re: std::msync
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 13 of 19 Topic 1373 of 4090
Post > Topic >>

Re: std::msync

by Alexander Terekhov <terekhov@[EMAIL PROTECTED] > Apr 6, 2005 at 08:58 PM

< Forward Inline >

-------- Original Message --------
Message-ID: <42527847.92E3B24D@[EMAIL PROTECTED]
>
Subject: Re: Lock-free shared_ptr on g++/x86, test/review needed
References: ... <021601c539cc$c8a5ae20$6501a8c0@[EMAIL PROTECTED]
>

Peter Dimov wrote:
[...]
> Yes, but in this case threads are not a problem (we're in release,
> destroying the last remaining shared_ptr; if we read weak_count_ == 1,
no
> other thread can be creating/destroying weak pointers because of basic
> guarantee). Msync is not a problem because we've just acquired in the
> decrement.

Yeah. Hello Peter, remember original

void release() throw() {
  if (!use_count_.decrement()) { // "full" release-acquire protocol
    dispose();
    if (!self_count_.decrement(msync::rel, count::may_not_store_min))
      destruct();
  }
}

?

(msync::rel on self_count_.decrement() was meant for "result is not 
min" case only; with ****d op for "old value == min + 1" case.) 

Sure, it can be safely transformed to 

void release() throw() {
  if (!use_count_.decrement()) { // "full" release-acquire protocol
    dispose();
    if (self_count_.load(msync::****d_competing) == 1 || // min == 0
        !self_count_.decrement(msync::rel))
      destruct();
  }
}

but ...

> 
> Now that I think of it, compiler value propagation isn't a problem
either
> because of the "memory" clobber on the decrement. So the cast to
volatile
> can be removed.
> 
>     void release() // nothrow
>     {
>         if( atomic_exchange_and_add( &use_count_, -1 ) == 1 )
>         {
>             dispose();
> 
>             if( weak_count_ == 1 ) // no weak ptrs

(this doesn't convey the notion of (potentially) competing accesses; who 
says that implementation can't read it bit-after-bit-and-sum-it, bytes 
aside for a moment... just for the sake of breaking your logic?)

>             {
>                 destroy();
>             }
>             else
>             {
>                 weak_release();
>             }
>         }
>     }

.... you also have and manage client-provided "deleter" objects and 
I see no reason why weak_ptr clients may NOT have access to them 
(resulting in similar problem with respect to access and 
destruction as with Whitehead's mutex). 

So to be safe, you need

void release() throw() {
  if (!use_count_.decrement()) { // "full" release-acquire protocol
    dispose();
    if (self_count_.load(msync::ccacq) == 1 || // min == 0
        !self_count_.decrement()) // "full" release-acquire protocol
      destruct();
  }
  // "full" means either "value dependent" or fully-fenced operation
}

So again, 

http://gcc.gnu.org/ml/libstdc++/2005-04/msg00000.html

I suggest that you hide that access in asm (and consider using the 
same operation in weak_release() too... for the sake of KISS-on-IA32 
and "easy" ****ting to RISC archs, where "count::may_not_store_min" 
is surely better in both release() and weak_release()).

regards,
alexander.
 




 19 Posts in Topic:
std::msync
Alexander Terekhov <te  2004-09-20 11:09:20 
Re: std::msync
"SenderX" <x  2004-09-20 18:39:58 
Re: std::msync
"SenderX" <x  2004-09-20 18:42:53 
Re: std::msync
Alexander Terekhov <te  2004-11-04 23:38:31 
Re: std::msync
Alexander Terekhov <te  2005-02-18 13:36:32 
Re: std::msync
Alexander Terekhov <te  2005-03-30 19:24:51 
Re: std::msync
Alexander Terekhov <te  2005-03-31 19:25:40 
Re: std::msync
Alexander Terekhov <te  2005-04-01 00:55:52 
Re: std::msync
Alexander Terekhov <te  2005-04-01 01:11:10 
Re: std::msync
Alexander Terekhov <te  2005-04-01 13:35:46 
Re: std::msync
"Peter Dimov" &  2005-04-02 14:23:01 
Re: std::msync
Alexander Terekhov <te  2005-04-02 17:29:47 
Re: std::msync
Alexander Terekhov <te  2005-04-06 20:58:38 
Re: std::msync
Alexander Terekhov <te  2005-04-06 20:59:48 
Re: std::msync
Alexander Terekhov <te  2005-04-11 13:07:47 
Re: std::msync
"Peter Dimov" &  2005-04-11 14:48:51 
Re: std::msync
Alexander Terekhov <te  2005-04-11 15:01:58 
Re: std::msync
"Peter Dimov" &  2005-04-02 17:43:36 
Re: std::msync
Alexander Terekhov <te  2005-04-02 17:07:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 11:01:54 CDT 2008.