From owner-freebsd-questions@freebsd.org Wed Aug 7 04:32:56 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 76CF0BDED6 for ; Wed, 7 Aug 2019 04:32:56 +0000 (UTC) (envelope-from mafsys1234@gmail.com) Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 463JX74z26z4Cjl for ; Wed, 7 Aug 2019 04:32:55 +0000 (UTC) (envelope-from mafsys1234@gmail.com) Received: by mail-pl1-x644.google.com with SMTP id c14so38678280plo.0 for ; Tue, 06 Aug 2019 21:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=4uAupBTMWr7BaUh9WJ10QICIA59b2F5FGZTUKrKQ5z4=; b=TYaBGNhFYGOODB+y/RNfrXh8sFBW7SW7dHF/W1eq3cpnXbfe+wQ9MY7+f3u9DAAvpI vXdmrprvECJXcQ1u0W9qIR6KO9HUxF0xEGjh7iZ3M194wH/FhxUygCStwgSEy1uxnMic OFPEiWUp9+poza8oDDz4hsSgZxWUlIfVzxZHepD01PqC77d0XiMFHlouh+ZCz4eRvK8i DfwVIx6hgwV9cGkfLUUWe4I5bSphlnpRGLwqpS9r1kNW7breAMpBMbKWk568pMKyEGD9 qtFvdpvhZt7DJigy0D1cMrO2gHbMfS95PYZmikQCULbqLc6Q709SZoIyrhjAu3ZVCFUk FhAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4uAupBTMWr7BaUh9WJ10QICIA59b2F5FGZTUKrKQ5z4=; b=pxpBzF9sCTGXeBBxfd9bZq1JRIEbCbnvD2rt0Uh6Dw/AXuJ51Fnpr8Inff3+Zr6Z9h kmFiiBBB4bNGjKBBp4wP3ntR7DpXdmJzp9L5KwIjLDNoQjvN1JG7D5s0vJr3GlNf6Tcw vExeoWMx4VTKmgtt7C1Gz/smZjdmu5kXT2yL519aWx6cSn5sI42UsHjqUEN7+aG0A1Ny 9xGotbOWeBiWYfiCvgWuZslZca9xsxF2kRcOg6Z3Y4tuVNMLrxXnjX45R25P8c4OGh8H slndQ7Fw+T4Jscr+HHfcZkQVXANn8QWLdJSgQ9qvgNdFj6xMJwi2t87Gsw7z+ORQmTCs 6Qxw== X-Gm-Message-State: APjAAAW20EiLoWmv9FTFj2TOZklU3wa5aZYiPrcsp+RqTp/h9JA8N/Bq tYIFswo4R/zDTv6pX44c9hkTRY5w X-Google-Smtp-Source: APXvYqx6HbPkz8yNm+5RWYwr12StmmzzUeRK4j+P23wqWB1Ome498oXfWufhR2eJE1kK3c32MHJbMQ== X-Received: by 2002:a17:902:e512:: with SMTP id ck18mr6059718plb.53.1565152374383; Tue, 06 Aug 2019 21:32:54 -0700 (PDT) Received: from [192.168.1.10] ([210.11.155.251]) by smtp.gmail.com with ESMTPSA id s24sm48313489pgm.3.2019.08.06.21.32.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 21:32:54 -0700 (PDT) Subject: Re: mutex held in a thread which is cancelled stays busy To: freebsd-questions@freebsd.org References: <20190806165429.14bc4052.freebsd.ed.lists@sumeritec.com> <1FC05CEB-982F-484F-9E41-5A74FF564494@freebsd.org> <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> From: MJ Message-ID: Date: Wed, 7 Aug 2019 14:32:27 +1000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190807095521.23e79874.freebsd.ed.lists@sumeritec.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 463JX74z26z4Cjl X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=TYaBGNhF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of mafsys1234@gmail.com designates 2607:f8b0:4864:20::644 as permitted sender) smtp.mailfrom=mafsys1234@gmail.com X-Spamd-Result: default: False [-4.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-1.00)[-1.000,0]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(0.00)[ip: (-0.37), ipnet: 2607:f8b0::/32(-3.05), asn: 15169(-2.45), country: US(-0.05)]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; IP_SCORE_FREEMAIL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_IN_DNSWL_NONE(0.00)[4.4.6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Aug 2019 04:32:56 -0000 I just noticed this: pthread_mutexattr_getrobust (& Attr, &pres); Why are you passing &pres? It should be the address of PTHREAD_MUTEX_ROBUST (or PTHREAD_MUTEX_STALLED ?) I would expect you should get EINVAL when testing the above statement. The Freebsd manual says: "If successful, these functions return 0." Refer: PTHREAD_MUTEXATTR(3) On 7/08/2019 11:55 am, Erich Dollansky wrote: > Hi, > > On Tue, 6 Aug 2019 20:58:30 -0400 > Daniel Eischen wrote: > >>> On Aug 6, 2019, at 4:54 AM, Erich Dollansky >>> wrote: >>> >>> Hi, >>> >>> for testing purpose, I did the following. >>> >>> Start a thread, initialise a mutex in a global variable, lock the >>> mutex and wait in that thread. >>> >>> Wait in the main program until above's thread waits and cancel it. >>> >>> Clean up behind the cancelled thread but leave intentional the mutex >>> locked. >>> >>> I would have expected now to get an error like 'EOWNERDEAD' doing >>> operations with that mutex. But I get 'EBUSY' as the error. >> >> Are you initializing the mutex as a robust mutex, via >> pthread_mutexattr_setrobust()? Are you using _lock() or _trylock()? >> >> For _trylock(), you only get EOWNERDEAD for robust mutexes. It seems >> that you should get EOWNERDEAD for _lock() in this case, so if that's >> what you're doing, it sounds like it might be a bug. >> > I did both. One time with initialising the mutex with its defaults by > handing over NULL as the attribute setting and one time with the > attributes set. > > I use this line to set the attribute: > > pres = pthread_mutexattr_setrobust (& Attr, PTHREAD_MUTEX_ROBUST); > > The following line: > > pthread_mutexattr_getrobust (& Attr, &pres); > > Sets pres also to 1. > > I am doing this on 12.0-STABLE FreeBSD 12.0-STABLE r350391 GENERIC > amd64 with the systems standard compiler. > > Is this the corrent way of doing it? > > Erich > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" >