Date: Wed, 31 Oct 2007 08:32:48 -0700 From: Bakul Shah <bakul@bitblocks.com> To: Alfred Perlstein <alfred@freebsd.org> Cc: Poul-Henning Kamp <phk@phk.freebsd.dk>, Garance A Drosehn <gad@FreeBSD.org>, freebsd-arch@FreeBSD.org Subject: Re: C++ in the kernel Message-ID: <20071031153248.4395A5B59@mail.bitblocks.com> In-Reply-To: Your message of "Tue, 30 Oct 2007 13:12:29 PDT." <20071030201229.GA33488@elvis.mu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> > > > 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!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071031153248.4395A5B59>