From owner-freebsd-stable@freebsd.org Thu Sep 3 08:19:59 2015 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6CDBE9C929D; Thu, 3 Sep 2015 08:19:59 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DAB59159D; Thu, 3 Sep 2015 08:19:58 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t838JmPa024872 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 3 Sep 2015 11:19:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua t838JmPa024872 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t838Jlx0024871; Thu, 3 Sep 2015 11:19:47 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 3 Sep 2015 11:19:47 +0300 From: Konstantin Belousov To: Erich Dollansky Cc: freebsd-threads@freebsd.org, FreeBSD stable Subject: Re: pthread_cancel / sleep change in behaviour Message-ID: <20150903081947.GB2072@kib.kiev.ua> References: <20150903080047.16be939e@X220.alogt.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150903080047.16be939e@X220.alogt.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2015 08:19:59 -0000 On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote: > Hi, > > I noticed a change in behaviour when calling pthread_cancel for a > thread which is sleeping using i.e. sleep (). > > How I understand pthread_cancel, it should cancel the thread and call > the clean up handler soon after its return. Important is that the > cancelled thread waited on a cancellation point. > > When I started testing our application under error conditions, I found > problems I could not explain. As the application's target is a > Raspberry, some tests have been done on a 10.1 on the Raspberry and > some on a amd64 machine running 10.2 STABLE. The behaviour on the > Raspberry was as expected but not on the amd64. > > The situation is now that there are always pairs of threads. One thread > does the work, the other thread just does a sleep() and cancels the > worker thread at the end. But, when the worker thread finishes its work > normally, it cancels the sleeping thread and then returns. > > After some time of testing I found out that pthread_cancel calls the > clean up handler of the sleeping thread only after sleep()'s return > when running on 10.2 STABLE on amd64 but calls the clean up handler > soon after cancellation on 10.1 on the Raspberry. > > Is this change of behaviour a feature or a bug? Provide a minimal example demonstrating the issue.