Re: Threading in BGWorkers (!)

From: James Sewell <james(dot)sewell(at)jirotech(dot)com>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Threading in BGWorkers (!)
Date: 2020-07-02 06:39:22
Message-ID: CAANVwEvRTK2EXa8e5wg6pEj+LyAv8u3SD+xDJNm=vc2eY6N0Pg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

In the hope of this not being derailed by larger/more unpopular pieces of
work, I'm attaching a tiny patch which I don't believe will have any
negative impact - but will remove one blocker for $subject (sigprocmask
usage is "unspecified" in multithreaded code [1]).

The patch replaces *sigprocmask *with *pthread_sigmask*. They have
identical APIs ("[pthread_sigmask] shall be equivalent to sigprocmask(),
without the restriction that the call be made in a single-threaded
process"[1])

The rationale here is that as far as I can tell this is the **only**
blocker to using multithreaded code in a BGWorker which can't be avoided by
adhering to strict code rules (eg: no PG calls from non-main threads, no
interaction with signals from non-main threads).

Before this went in the rules would need to be agreed upon and documented -
but hopefully it's at least a way forward / a way to progress this
discussion.

Cheers,
James

[1]
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html

--
The contents of this email are confidential and may be subject to legal or
professional privilege and copyright. No representation is made that this
email is free of viruses or other defects. If you have received this
communication in error, you may not copy or distribute any part of it or
otherwise disclose its contents to anyone. Please advise the sender of your
incorrect receipt of this correspondence.

Attachment Content-Type Size
pthread_sigmask.patch application/octet-stream 441 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2020-07-02 07:52:45 Re: A patch for get origin from commit_ts.
Previous Message Pavel Stehule 2020-07-02 05:47:48 Re: SQL-standard function body