Maxim Dounin
October 07, 2021 01:18PM
Hello!

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

> > -----Original Message-----
> > From: nginx-devel <nginx-devel-bounces@nginx.org> On Behalf Of Maxim Dounin
> > Sent: Thursday, 7 October 2021 16:07
> > To: nginx-devel@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/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Sending a notification to the main nginx thread

erankor 594 October 05, 2021 10:06AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 234 October 06, 2021 09:12AM

RE: Sending a notification to the main nginx thread

erankor 373 October 06, 2021 03:54PM

Re: Sending a notification to the main nginx thread

Maxim Dounin 284 October 07, 2021 09:08AM

RE: Sending a notification to the main nginx thread

erankor 353 October 07, 2021 11:18AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 246 October 07, 2021 01:18PM

RE: Sending a notification to the main nginx thread

erankor 347 October 07, 2021 03:48PM

Re: Sending a notification to the main nginx thread

dnj0496 310 October 07, 2021 01:28PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 298
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready