From owner-freebsd-stable@freebsd.org Thu Sep 3 01:14:44 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 2F3D49C9633; Thu, 3 Sep 2015 01:14:44 +0000 (UTC) (envelope-from erichsfreebsdlist@alogt.com) Received: from alogt.com (alogt.com [69.36.191.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1097B90A; Thu, 3 Sep 2015 01:14:43 +0000 (UTC) (envelope-from erichsfreebsdlist@alogt.com) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=alogt.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Subject:Cc:To:From:Date; bh=sJcO9n364yQ2nEU0xg8NR71+d42zcxZT1JiyS/0Xvno=; b=c2CGdHjpEoDqbXtcb4/a5Jt6yQp3c00EXtg3Lx10kUGptQzPcQGF77Cv89BMra6N9ogRL1ObJ/RVAe5hGCNu2v3nuy/OOyCD5oYLdMbLeYvzhWkZfHQS3q9vwpgR/xweiVJtO11DkQEME/qKkQmOq4qnzXcUpK7VBh2B80dWQAM=; Received: from [114.124.38.120] (port=27026 helo=X220.alogt.com) by sl-508-2.slc.westdc.net with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1ZXHxV-003UgK-Qt; Wed, 02 Sep 2015 18:00:54 -0600 Date: Thu, 3 Sep 2015 08:00:47 +0800 From: Erich Dollansky To: freebsd-threads@freebsd.org Cc: FreeBSD stable Subject: pthread_cancel / sleep change in behaviour Message-ID: <20150903080047.16be939e@X220.alogt.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sl-508-2.slc.westdc.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - alogt.com X-Get-Message-Sender-Via: sl-508-2.slc.westdc.net: authenticated_id: erichsfreebsdlist@alogt.com X-Source: X-Source-Args: X-Source-Dir: 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 01:14:44 -0000 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? Erich