From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Raeburn Newsgroups: gmane.lisp.guile.devel Subject: Re: thread safe functions Date: Sat, 21 Aug 2010 20:57:46 -0400 Message-ID: <8C8EEFE6-77CA-42E7-A2FB-9CEF4E83CDFF@raeburn.org> References: <20100805112743.GA1671@securactive.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1282438689 9788 80.91.229.12 (22 Aug 2010 00:58:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 22 Aug 2010 00:58:09 +0000 (UTC) To: guile-devel Development Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Aug 22 02:58:08 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Omysy-0002ro-35 for guile-devel@m.gmane.org; Sun, 22 Aug 2010 02:58:08 +0200 Original-Received: from localhost ([127.0.0.1]:53027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Omysx-0005Z3-J4 for guile-devel@m.gmane.org; Sat, 21 Aug 2010 20:58:07 -0400 Original-Received: from [140.186.70.92] (port=43630 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Omysq-0005Yg-A8 for guile-devel@gnu.org; Sat, 21 Aug 2010 20:58:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Omysp-0001Oo-4B for guile-devel@gnu.org; Sat, 21 Aug 2010 20:58:00 -0400 Original-Received: from splat.raeburn.org ([69.25.196.39]:34877 helo=raeburn.org) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Omysd-0001MJ-Rj for guile-devel@gnu.org; Sat, 21 Aug 2010 20:57:59 -0400 Original-Received: from squish.raeburn.org (squish.raeburn.org [10.0.0.172]) by raeburn.org (8.14.3/8.14.1) with ESMTP id o7M0vk3o016822; Sat, 21 Aug 2010 20:57:46 -0400 (EDT) In-Reply-To: X-Mailer: Apple Mail (2.1081) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:10785 Archived-At: (switching to guile-devel from guile-user since I think this is more of = a developers' issue) On Aug 18, 2010, at 11:56, Andy Wingo wrote (quoting the manual): > Thus, you need to put in additional synchronizations when = multiple > threads want to use a single hashtable, or any other mutable Scheme > object. Unfortunately this applies to some internals of the implementation too. = For example, "set-object-property!" and friends use a hash table and = assoc lists internally. There's a "critical section" protecting the = assoc list manipulation in set-object-property!, but nothing else; I = doubt using it on two objects not already in the hash table is safe (in = the sense of both concurrent calls taking effect, as if made serially in = unspecified order), based on the text Andy quoted about hash tables. = But application code calling set-object-property! isn't explicitly = operating on a mutable Scheme object (and a Scheme coder might = reasonably assume that the properties were stored with the object, not = in a global hash table), so the above advice from the manual doesn't = seem to apply. scm_c_issue_deprecation_warning and scm_c_register_extension don't look = thread-safe to me (in the sense described above). Both maintain linked = lists without locking, and these aren't even implicitly Scheme objects. = Both risk losing the new list entries in the face of concurrent calls. That's just from a spot check; I'm not even trying to be thorough. And don't get me going on memory ordering models.... To be honest, I wouldn't trust libguile in a multithreaded application = without much more careful analysis, not just of the code, but of the = assumptions being made and whether they're actually valid for various = processors (not just the relatively friendly x86) and compilers. = Without that sort of analysis, I think "use mutexes everywhere" is the = only safe approach, and libguile certainly isn't doing that. Ken=