Welcome! Log In Create A New Profile

Advanced

RE: Sending a notification to the main nginx thread

October 06, 2021 03:54PM
>
> -----Original Message-----
> From: nginx-devel <nginx-devel-bounces@nginx.org> On Behalf Of Maxim Dounin
> Sent: Wednesday, 6 October 2021 16:12
> To: nginx-devel@nginx.org
> Subject: Re: Sending a notification to the main nginx thread
>
> Hello!
>
> First of all, you may want to take a look at this warning in the development guide:
>
> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnginx.org%2Fen%2Fdocs%2Fdev%2Fdevelopment_guide.html%23threads_pitfalls&amp;data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285308685%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=%2BiDgCqNY6Wtl0elz%2FYAG7UvdOmoW%2BsZg9v0i5Oicc%2FY%3D&amp;reserved=0
>
> Quoting it here:
>
> It is recommended to avoid using threads in nginx because it will definitely break things: most nginx functions are not thread-safe. It is expected that a thread will be executing only system calls and thread-safe library functions.
> If you need to run some code that is not related to client request processing, the proper way is to schedule a timer in the init_process module handler and perform required actions in timer handler. Internally nginx makes use of threads to boost IO-related operations, but this is a special case with a lot of limitations.
>
Thanks Maxim, I completely get that, that is the reason I was looking for way to send a notification to the main thread, and didn't just try to call nginx functions from some other thread.
In my case, I need to integrate with some 3rd party library that has its own event loop, it would require significant changes to the library to make it run inside nginx's event loop...
So, my plan is to run it on a side thread, and send notifications between the threads, which would trigger some handler on the main thread whenever new data arrives.
I can use ngx_notify for this, but if someone will use the module and also nginx's thread pool or some 3rd party module that uses ngx_notify, it will break.
I think I can live with that, but would be nice to have a solution that is complete.

Eran

>
> --
> Maxim Dounin
> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmdounin.ru%2F&amp;data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=j6ifgLEZxh6B60ZP2wGOoJMnb1JnaVig3Ja26LNoMk0%3D&amp;reserved=0
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailman.nginx.org%2Fmailman%2Flistinfo%2Fnginx-devel&amp;data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=dOXGqrvoFn8AnO1CGa67SCgmoiqIUdoNU8Aw9t6xGcA%3D&amp;reserved=0
>
_______________________________________________
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 251 October 05, 2021 10:06AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 68 October 06, 2021 09:12AM

RE: Sending a notification to the main nginx thread

erankor 95 October 06, 2021 03:54PM

Re: Sending a notification to the main nginx thread

Maxim Dounin 103 October 07, 2021 09:08AM

RE: Sending a notification to the main nginx thread

erankor 85 October 07, 2021 11:18AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 74 October 07, 2021 01:18PM

RE: Sending a notification to the main nginx thread

erankor 76 October 07, 2021 03:48PM

Re: Sending a notification to the main nginx thread

dnj0496 57 October 07, 2021 01:28PM



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

Online Users

Guests: 53
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready