From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id BDB8038582BF for ; Mon, 1 Aug 2022 20:13:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BDB8038582BF Received: by mail-pg1-x532.google.com with SMTP id bh13so10616340pgb.4 for ; Mon, 01 Aug 2022 13:13:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ehfWaaFjvxbiMl5nQCMarz4lzz+G5UUzHokHZ/6//Ls=; b=k0ADpoQHbFCNP23dAwNeprDzNXlJT6UtTfIFDqsJJusnVnEjNM/oP02feXx83KiqcF MzJthxRn3G8bfbWJhh3922oeBhHfZemuQZ2LIJPZSEGMtLptWTertHPFSl4xnj4tr7Ea JJOG/00Oc2rLFV8Dkji5vILe14KUGJqbZQUYga9cbisYbnCo8vEYkTwrpV+8d7tA77/a OaqWSJLkqiVWqS1MCvB8U5Aj1qMTs44Ifc28+ayXYbdqm8TVw1EYVTqB9FEqe7++hYrI HL3qEkz11Xtatt95McoAdIvfR5xwuoSuYga6G/5sgSP4bkB+1WxoAsIeMhyQsCdchEsg q7wA== X-Gm-Message-State: ACgBeo1QGV6TbxCz32B0BXUHOTaD+AxeSRnJiqeEfdpq+SPc3JUF4KMn BpWcSBr1vDTEUy/xKKflQMs/Jf4SuaVg4Nj9YbZH2a+Zsn4= X-Google-Smtp-Source: AGRyM1vr8+8Ku0IOWOpGPIoCB1KXMW4dwh2onV75jfCqJzE/jjEFP+2xL/HHsA/26TNEBUG4hTDNxnfvKv45tu5n/4s= X-Received: by 2002:a05:6a00:f85:b0:52a:c718:ff9 with SMTP id ct5-20020a056a000f8500b0052ac7180ff9mr17433456pfb.85.1659384833664; Mon, 01 Aug 2022 13:13:53 -0700 (PDT) MIME-Version: 1.0 References: <9f29c0c4-7b2a-3d95-5a62-837b5c352d79@embedded-brains.de> In-Reply-To: From: =?UTF-8?B?Sm/Dq2wgS3LDpGhlbWFubg==?= Date: Mon, 1 Aug 2022 22:11:15 +0200 Message-ID: Subject: Re: pthread_mutex_timedlock() vs. clock_settime() To: Sebastian Huber Cc: libc-help@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2022 20:13:56 -0000 Hi Sebastian, I am unsure where are your doubts in what I told you: #1 conditional locks always use 2 condition variables with logical and #2 signal only waiting conditions The points above apply to any conditional lock. Thought, there is an exception for synchronized threads. But your threads aren't synchronized. If your conditional lock is invoked more than once: #3 do initial sync #4 provide additional variables to avoid override by previous run. Yes, we need some tuples. If you use three you can even detect dead-locks. #5 your threads may run on a different CPU even physically. You need atomic operations. I am willing to do further explanation, but what I am telling you is based on experience with AgsThread::clock() https://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/thread/ags_thr= ead.c?h=3D4.3.x#n2302 This code was reworked by me different times to fine tune it. First I was using the POSIX API and migrated later to GLib. regards, Jo=C3=ABl On Mon, Aug 1, 2022 at 6:31 PM Sebastian Huber wrote: > > Hello Jo=C3=ABl, > > this is just a test case and not a real application. There is only a > main thread and a worker thread. The worker thread should just block on > an synchronization object and then wait for a time out (or it is > cancelled). The main thread uses a simple sleep(1) to hopefully ensure > that the worker task had enough time to block on the synchronization > object under test. There are different action and done events. Since a > mutex is used, there is no need for atomic objects. > > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.huber@embedded-brains.de > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht M=C3=BCnchen > Registernummer: HRB 157899 > Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler > Unsere Datenschutzerkl=C3=A4rung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/