Sending a notification to the main nginx thread

Maxim Dounin mdounin at mdounin.ru
Thu Oct 7 17:17:00 UTC 2021


Hello!

On Thu, Oct 07, 2021 at 03:16:37PM +0000, Eran Kornblau wrote:

> > -----Original Message-----
> > From: nginx-devel <nginx-devel-bounces at nginx.org> On Behalf Of Maxim Dounin
> > Sent: Thursday, 7 October 2021 16:07
> > To: nginx-devel at nginx.org
> > Subject: Re: Sending a notification to the main nginx thread
> > 
> > Hello!
> > 
> > To re-iterate: inside a "side thread" you are not allowed to call any non-thread-safe libc functions.  It is reasonable to assume this excludes all 3rd party libraries with their own even loops.
> 
> This is a valid point. 
> 
> I checked it out, with the specific build options I'm using on Linux, these are the non-thread-safe libc functions used by nginx -
> (list of all non-thread-safe functions taken from https://man7.org/linux/man-pages/man7/pthreads.7.html, assuming POSIX.1-2008) -
> 
> $ (objdump -T /usr/local/nginx/sbin/nginx | grep GLIBC | awk '{print $NF}' ; cat /tmp/libc-non-thread-safe) | sort | uniq -c | grep -vw 1
>       2 dlerror
>       2 getenv
>       2 getgrnam
>       2 getpwnam
>       2 localtime
>       2 strerror
> 
> First 4 functions are called only early on nginx startup from what I see, so not relevant in this context.
> That leaves me only with strerror & localtime. 
> 
> I verified these 2 functions are not used by the specific library I'm linking against.
> So, assuming I don't use any nginx functions on the side thread (other than ngx_notify), it feels quite safe to me...

In no particular order:

- Assuming nginx uses only POSIX functions is wrong, it does use 
  platform-specific functions and various portable functions not 
  specified by POSIX, such as 

- The above objdump results look incorrect: for example, nginx 
  certainly uses readdir(), which is in the POSIX non-thread-safe 
  list, but not in your list.

- There are other libraries nginx uses, which makes the problem 
  much worse.

If you insist on using threads in your module - you are free to do 
so, you were warned and it's your choice.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list