From owner-freebsd-arch@FreeBSD.ORG Tue Oct 30 18:11:25 2007 Return-Path: Delivered-To: freebsd-arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88C8416A420; Tue, 30 Oct 2007 18:11:25 +0000 (UTC) (envelope-from bakul@bitblocks.com) Received: from mail.bitblocks.com (ns1.bitblocks.com [64.142.15.60]) by mx1.freebsd.org (Postfix) with ESMTP id 6047A13C4DD; Tue, 30 Oct 2007 18:11:25 +0000 (UTC) (envelope-from bakul@bitblocks.com) Received: from bitblocks.com (localhost.bitblocks.com [127.0.0.1]) by mail.bitblocks.com (Postfix) with ESMTP id EC35B5B30; Tue, 30 Oct 2007 11:11:24 -0700 (PDT) To: Alfred Perlstein In-reply-to: Your message of "Tue, 30 Oct 2007 10:37:35 PDT." <20071030173734.GV33488@elvis.mu.org> Date: Tue, 30 Oct 2007 11:11:24 -0700 From: Bakul Shah Message-Id: <20071030181124.EC35B5B30@mail.bitblocks.com> Cc: Poul-Henning Kamp , Garance A Drosehn , freebsd-arch@FreeBSD.org Subject: Re: C++ in the kernel X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2007 18:11:25 -0000 > * Bakul Shah [071030 09:36] wrote: > > > > The structured macro paper referenced on the K wiki page also > > seems rather interesting. A powerful macro facility needs to > > be well integrated with the language (much like Lisp or > > Scheme's macros) so that you can write for instance > > > > 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: /* struct mtx lock is a non local object */ { mutex_lock(&lock); ... bar: ... if (cond1) goto _break11; ... if (cond2) goto _foo12; ... if (cond3) goto bar; ... if (cond4) goto _return13; // from enclosing function ... _break11: mutex_unlock(&lock); break; _foo12: mutex_unlock(&lock); goto foo; _return13: mutex_unlock(&lock); return; } ... foo: This as an example of what *I would want* a macro facility to do! Implementing such a facility would not be very hard (after all it is just tree surgery) but coming up with a macro language that is non-ugly is very hard and I do realize that. One level up, this is *one way* to achieve writing error free mutex code. Another is through some sort of static analysis tool. A third is through code walkthroughs. Each has different costs. > Just wondering how much of this we want to roll on on our own. So am I! But it is worth pursuing some of these threads at the discussion level. The more important point is the underlying "need" which we can all agree on (I hope!), which is to be able to write such code in an error free way. If we have such a list we can figure out which ones to focus on and how to satisfy them.