Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whUX5-000G9G-2F for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 15:49:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whUX4-007yWC-05 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jul 2026 15:49:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whUX3-007yW3-27 for pgsql-hackers@lists.postgresql.org; Wed, 08 Jul 2026 15:49:54 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1whUX1-00000000Aux-2saC for pgsql-hackers@postgresql.org; Wed, 08 Jul 2026 15:49:53 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4gwMwr4bczz49Q53; Wed, 08 Jul 2026 18:49:48 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783525789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w22zuKKJpOdNYT0UR98sQOopS+cwiI+5eDD8B0ck5Tc=; b=gHIf7TGRDo3sjq4awilk2/OOSV0E8/Wbrhut9/3zT9OLDHmUIjDaP6mnFR8gmIvmon2jy3 J+dL3sncggZZ4ZQK7rfVB6g01Oo3S411KU+n1gAu2F/lO8lLjtNbW9/938rh7r5HzZpa27 05IeWDiDO4atm5G2A4pEbbycW0VW8gyOlu4tSv7psJeTlIXyj5oCPEES0K1eRFfnSAjtQ1 oDHFMOEP1aePbyMJTTs8K6fT/ibRPY7Msb5tdBdTcbw78CqAw+eKx+jButwPpdh045lWhM 8IhILVHpnjsLD4q/yCQeROG84I2Fv9Qvh0XiQNrjzXqYffue101hYdRvZDu19g== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1783525789; b=v0BF8xO6KJbJHrXW0l6ms3ZblV/RWRCqMLMTs2V+dNPRdeVvyeFnPbWfxPpD0B/EAOD3JO 9eiuVwZL8FeoXzQZZqxlZDwM5+TN/GdjHrrfW+SB58vps0701dzIYNoX1pvKVnw7eottxx pJIeu/eiCroPCn+3oU2QG+zqGd/ZgZW4xCIVQmYlJOBYQQi1cdZO92AjvJYmVJbcF1h/U7 1J070GbtECrCFAGhHw7yxHbBMe72Wa90cmgB4ZJdzSD4LmOrzYFtonH9d8wMjt1aT6ccq3 aqmU2phx/9avRW63ZZfSR50qsZns/JH9LwCbie/lCJKJKeInL6kIBDhJ2M4drg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783525789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w22zuKKJpOdNYT0UR98sQOopS+cwiI+5eDD8B0ck5Tc=; b=Z4Uzrgpgoivm/2qSig6IUkY1X6hxV7fAwHrtLRuPpx7v2yL4B7ne/8ta4aB8ztd4ZBYmIr GOMMmSTb9BFAK63kua+eL7IuB8a9wBHjpxVwsEI+N8AqxoVCJO5y7gfQMJmWqL/pVn+IlW zhxU3TyWym2RUQuqQw1OhnUZVQHVB6UnSD/pSOtFrcJFQ2+ZW+N9N4VjxjwRAFibOHDFxg l5IH/J1FIbKq/IOgxOqiYj9ZU3MWMlPiepI2ssG3U7aTEeVaEMUSVOLJKvUuRQuc7sr5PG uH60zaAeDNZBVZBrT8X1YTRFTzhg62CoL8K3MnV5y5Q+Tjv2HF1XbYiVx8mkcg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <64ff0801-e6fb-4c4f-8bb8-67391e888860@iki.fi> Date: Wed, 8 Jul 2026 18:49:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can we get rid of TerminateThread() in pg_dump? To: Jelte Fennema-Nio , Thomas Munro Cc: Bryan Green , pgsql-hackers , Tom Lane , Kyotaro Horiguchi References: <56821e0d-bfd5-4619-b13f-12e28c78289b@iki.fi> <5e4a28ec-d5e1-4817-889c-b8aefe5f48ed@iki.fi> <400c93d2-0b81-4a0b-ac60-0fd6512d5b5d@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 08/07/2026 11:47, Jelte Fennema-Nio wrote: > On Wed, Jul 8, 2026, 01:41 Thomas Munro wrote: > >> On Tue, Jul 7, 2026 at 9:23 AM Heikki Linnakangas >> wrote: >> > In this case, though, I think all we need is a "volatile sigatomic_t" >> > flag. Sending the query cancellation over the network surely acts as a >> > full compiler and memory barrier in the cancelling thread. And >> similarly >> > receiving the error message from the network acts as a full barrier in >> > the other threads that might receive the cancellation error from the >> > backend. >> >> You're right.  So basically Jelte's patch, except it doesn't need the >> Win32 atomics stuff, just volatile, and a comment to explain that >> assumption.  (Then some later version could use an explicit barrier >> instead of a comment, I guess, just to be clearer.) > > Without any synchronization primitives there's still room for a > data-race, right? The network operations on the cancel thread (to send cancellation) and on the other thread (to receive the error messages from the server) should act as reliable memory barriers. > But I guess in practice that doesn't matter for the messages we > actually care about. Also true. > Attached is a patch with that change, altough I'm using "volatile > bool" instead of "volatile sigatomic_t" since there are no signal > handlers involved here. > > I also added !is_cancel_in_progress() checks in a few more places to > silence the places that Bryan had found. Ok, committed, thank you! > To be clear: putting all of these threads together I'd like to remove > this function again completely. Instead I'd like this to use > CancelRequested for this, but that requires my PQblockingCancel patchset > to be merged first. And then I'd like to make CancelRequested a C11 > atomic_flag instead of a volatile. Ack. I'm getting a little confused by all the interdependent patches flying around. But as long as we keep grinding, committing what we can one patch at a time and rebasing all remaining ones, we'll be done eventually :-). - Heikki