[cpp-threads] modes

Doug Lea dl at cs.oswego.edu
Sun May 8 11:41:40 BST 2005


> 
> No, this is impossible to optimize in general.
> 
> int f()
> {
>     Stuff * p = asp.read_acq();
> 
>     if( p != 0 )
>     {
>         return p->y;
>     }
>     else
>     {
>         return 0;
>     }
> }
> 
> The compiler has no idea whether the reads and writes in the caller of f() 
> can safely be hoisted across the explicit acquire.

Not usually a problem if you do inlining, dynamic compilation, and/or
interprocedural dataflow. And if you don't, then inability
to remove barrier is only an incremental cost over other
call overheads.

Overcoming this in general seems to entail the kinds of memory
mode qualifiers on functions that I mentioned that I don't know
how to do. In other words, I don't think we can solve the
opacity problem of separate compilation within the
confines of the memory model spec :-)

-Doug




More information about the cpp-threads mailing list