<div dir="ltr">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.<div><br></div><div>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):</div><div><br></div><div>Threading (may) be safe if:</div><div><ol><li>all signals will be delivered on the main thread and nowhere else</li><li>no postgres function will ever be called from anything that's not the main thread</li><li>it's safe for postgres to call any system library function, even ones explicitly marked as not thread safe</li><li>it's safe for postgres to call sigprocmask()</li></ol><div>I can live with 1. and 2 - they are fairly easy as long as you know the rules.<br></div></div><div><br></div><div>3. needs to be converted to a list of possible calls - which can be done and checked.</div><div><br></div><div>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?</div><div><br></div><div>Are there any other rules which need to be adhered to?</div><div><br></div><div>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.</div><div><br></div><div>James</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>

<br>
<hr style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14.5455px;line-height:normal"><font size="1" color="Gray" face="Arial" style="line-height:normal">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.</font>