C++ in the kernel
Bakul Shah
bakul at bitblocks.com
Wed Oct 31 08:58:09 PDT 2007
> > > > critical_section(lock) {
> > > > ...
> > > > bar:
> > > > ...
> > > > if (cond1) break;
> > > > ...
> > > > if (cond2) goto foo;
> > > > ...
> > > > if (cond3) goto bar;
> > > > ...
> > > > if (cond4) return; // from enclosing function
> > > > ...
> > > > }
> > > > ...
> > > > foo:
> > >
> > >
> > > do you mean like C++:
> > >
> > > do {
> > > critical_object critical_instance();
> > >
> > >
> > >
> > >
> > > }
> >
> > No idea but I can not see how that will do what I had in mind. A purely
> > lexical translation of the snippet I gave above would be something like:
>
> You can create an object on the stack that locks the mutex given
> to it like so:
>
> do {
> mtx_lock_object mtx_locker(&lock);
>
> }
>
> When the object is destroyed by stack popping, the lock will be freed.
>
> It's the same thing.
Yes indeed, thanks! I am starting to forget all the C++
tricks I learned. Mercifully. Two points though. This was
an example of what is possible with macros that can inspect
their argument code + they can also do many other things that
don't fit so easily with C++'s initialization/finalization
trick. For example what if you can't gain the lock and want
to do something else? Two, while C++ gives you a way to
solve this problem, it does it in a "clever" way, not an
obvious way.
But I will acknowledge I am comparing vaporware with
something that works now!
More information about the freebsd-arch
mailing list