[cpp-threads] Memory model counterproposal: bit-fields

Peter Dimov pdimov at mmltd.net
Fri May 27 10:59:54 BST 2005


Boehm, Hans wrote:
> As far as the programming model is concerned, I think I could
> live with Peter's formulation, so long as it's clear that it
> doesn't apply to bit-fields of nested structs.  The statement is
> certainly simple enough.  But it still seems
> to me that it allows significantly more surprising behavior,
> for relatively minimal gain.
>
> For example, if I have an interface that uses an
> opaque (to the client) struct r to hold a request and its result,
> where
>
> make_request(r&)
>
> makes the request, and
>
> get_result(r&)
>
> retrieves the result, I can put an r in a struct with a bit field
> only if there is no concurrency involved, even though one would
> really expect that to be transparent to the client.

I think that it might be acceptable. The idiom would be to always put 
bitfields in their own nested struct.

struct X
{
    R r;

    struct Bf
    {
        int v: 30;
        int w: 2;
    } bf;
};

or something like that.





More information about the cpp-threads mailing list