From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 8 16:58:55 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9D0CC2CB; Tue, 8 Apr 2014 16:58:55 +0000 (UTC) Received: from mail-bk0-x236.google.com (mail-bk0-x236.google.com [IPv6:2a00:1450:4008:c01::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F123917DD; Tue, 8 Apr 2014 16:58:54 +0000 (UTC) Received: by mail-bk0-f54.google.com with SMTP id 6so825205bkj.13 for ; Tue, 08 Apr 2014 09:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=NHvC0UcNkDKcX3OMSKyzFLCQC/W9lfU+L+CUQAhx2f8=; b=mpdQjKGCrkt+Pa1aWnZqM6ADF/PYzqFC6MI0q+SdItmRqqiJN20gjT2gR0Q3RVBTbi 4ycN5Cv0BlRyUwO4m4osqDjywR//tadAEw1WpDAduGuV/Y0DyXICLcQJas7+pQLE7MtQ GDwsuEdeS3pzp0ebA7nh9z/k8db/1Un3rJCJKOipljqs1NvqFfcDaRkSvoQLRJelT6ae VK76e0ECyyz5lB17wx5jYpXlzcGk3JoGocA5ohooM4q42lStL/JuC37TDGlrOvBjFsrV ncxNgYypiVmkaPsqQqxFrDrq472LJarbSd8kpGmtoRX1FfEuD3tXUbjC9DwKR6g9ipbI +HUw== MIME-Version: 1.0 X-Received: by 10.112.85.6 with SMTP id d6mr3468006lbz.8.1396976333120; Tue, 08 Apr 2014 09:58:53 -0700 (PDT) Received: by 10.112.145.39 with HTTP; Tue, 8 Apr 2014 09:58:53 -0700 (PDT) In-Reply-To: <0D69A6A8-43D1-41FB-8C2D-00F5CAD9C86E@FreeBSD.org> References: <0D69A6A8-43D1-41FB-8C2D-00F5CAD9C86E@FreeBSD.org> Date: Tue, 8 Apr 2014 12:58:53 -0400 Message-ID: Subject: Re: Multiple locks and missing wakeup. From: vasanth sabavat To: =?ISO-8859-2?Q?Edward_Tomasz_Napiera=B3a?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Cc: hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Apr 2014 16:58:55 -0000 Hi, I assume you are in a situation where one of your lists is being accessed by many producer threads and only one thread is consuming both lists? In your context, wouldn't it be easier to use two separate threads to process each individual lists? This is assuming you want to avoid contention to one list which is accessed by many threads. On Tue, Apr 8, 2014 at 2:34 AM, Edward Tomasz Napiera=C5=82a wrote: > Let's say I have a kernel thread processing elements from a queue, > sleeping until there is work to do; something like this: > > mtx_lock(&mtx1); > for (;;) { > while (!LIST_EMPTY(&list1)) { > elt =3D LIST_FIRST(&list1); > do_stuff(elt); > LIST_REMOVE(&list1, elt); > } > sleep(&list1, &mtx1); > } > mtx_unlock(&mtx1); > > Now, is there some way to make it work with two lists, protected > by different mutexes? The mutex part is crucial here; the whole > point of this is to reduce lock contention on one of the lists. The > following code would result in a missing wakeup: > > mtx_lock(&mtx1); > for (;;) { > while (!LIST_EMPTY(&list1)) { > elt =3D LIST_FIRST(&list1); > do_stuff(elt); > LIST_REMOVE(&list1, elt); > } > > mtx_lock(&mtx2); > while (!LIST_EMPTY(&list2)) { > elt =3D LIST_FIRST(&list2); > do_other_stuff(elt); > LIST_REMOVE(&list2, elt); > } > mtx_unlock(&mtx2); > > sleep(&list1, &mtx1); > } > mtx_unlock(&mtx1); > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= " > --=20 Thanks, Vasanth