Re: Use Lock
- From: Ulrich Eckhardt <doomster@xxxxxxxx>
- Date: Tue, 21 Mar 2006 21:57:56 +0100
David Alasiga wrote:
C++ for example allows you some really neat tricks that make the
compiler check that you first acquire a lock and then start
reading/writing.
I use C++. It sounds very interesting idea. Could you tell me how to do
it? Thanks for your reply.
Ian mentioned a facade - while I'm not sure if that is what it's called,
his description was what I had in mind. Basically, you provide a single
channel to the shared data (e.g. a function) that then returns a proxy
object. This proxy object does the locking and unlocking and further it
has e.g. an overloaded operator-> like a smart pointer that then gives you
access to the data.
There is another way that uses the fact that 'volatile' when applied to an
aggregate mostly works like 'const' does. As example, you can't call a
function via a reference to a volatile object unless the function is also
marked as volatile, just like you can't invoke a function unless it's
const when you have a reference to a const object. If you wrap the removal
of volatile and the locking into a struct or function, you won't be able
to use the object except for the few functions marked as volatile, too.
Combining this with the above, maybe using 'friend' to fine-tune access,
gives even greater security against abuse.
Uli
.
- References:
- Use Lock
- From: David Alasiga
- Re: Use Lock
- From: Ulrich Eckhardt
- Re: Use Lock
- From: David Alasiga
- Use Lock
- Prev by Date: Software scalibility
- Next by Date: Re: "give me work" model
- Previous by thread: Re: Use Lock
- Next by thread: How many thread I can create
- Index(es):
Relevant Pages
|