[postgis-devel] Threading in BGWorkers

James Sewell james.sewell at jirotech.com
Sun Jun 21 23:40:05 PDT 2020


I was talking about PostgreSQL and threading on IRC the other day - which I
know is a frowned upon topic, but I just wanted to frame the same questions
here and hopefully get a discussion going.

On IRC RhodiumToad offered the following advice (after a standard there be
dragons here disclaimer, as well as noting this may not be a complete list):

Threading (may) be safe if:

   1. all signals will be delivered on the main thread and nowhere else
   2. no postgres function will ever be called from anything that's not the
   main thread
   3. it's safe for postgres to call any system library function, even ones
   explicitly marked as not thread safe
   4. it's safe for postgres to call sigprocmask()

I can live with 1. and 2 - they are fairly easy as long as you know the
rules.

3. needs to be converted to a list of possible calls - which can be done
and checked.

4. is not fine, as I think Postgres would need to be
using  pthread_sigmask() instead - given looks like a one line change
could  pthread_sigmask be used when available?

Are there any other rules which need to be adhered to?

Any thoughts, comments, dire warnings, hand waving? On IRC the general
thought was that any changes could be seen as encouraging threading which
is a bad thing - I would argue if you're writing BGWorkers which have SPI
access you've already got a wide band to screw things up in anyway.

James

-- 
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20200622/ae24585c/attachment.html>


More information about the postgis-devel mailing list