Boost logo

Boost :

Subject: Re: [boost] [lockfree] review
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2011-08-09 00:47:46


>
> Who is "we," Kimosabe?
>

Almost all other programmers, I think.

> I *really* don't think about code that way. I generally try to avoid
> writing code that makes me think about the order in which things happen.
>

I believe you. But I expect you are the exception.
So to understand some of the difficulties people have with lockfree, I think
first you would need to get into the sequential habit, only to understand
what it is like to break th habit. Like taking up smoking to know what it
is like to quit.

If you instead think more about state/invariants, then the hard part might
only be giving up areas of protection (member functions/locks) where you can
break the invariants. And give up some things that would normally be made
part of the invariant. Like a pointer managing a list. Allow the temporary
state in the middle of an add to be exposed to another operation (in a way
that all operations can still manage).
Often the invariants become complicated conditions - "either the pointer is
valid or the counter is odd or ..." yet you can't check them all in a single
operation.
And then sometimes you do use order - ie if I read the counter, then the
pointer , then re-read the counter, and the counter hasn't changed, then the
pointer if valid (assuming proper barriers).
It helps if you like logic puzzles (which are also often easier if you draw
state diagrams of some kind - hmmm).

So invariant management with very little room to temporarily break them.

Anyhow, I think I strayed off topic. And I'll just go further... It is
interesting to me to understand how other programmers think. I don't think
much about order, or invariants, or state; I spend most time thinking about
how the pieces of code fit together - or more importantly, stay apart.

Tony


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk