I have 3rd party library, which is nonblocking and has its own event loop, it accepts pointer of callback function and executes it in same thread. What I want is to post event from this thread to nginx main thread, something like ngx_add_timer but without time option, to safely add event to nginx main event loop.
Post event to nginx event loop from another thread
417 Views Asked by frx At
1
There are 1 best solutions below
Related Questions in MULTITHREADING
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
Related Questions in NGINX
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
Related Questions in EVENT-HANDLING
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
Related Questions in NGINX-MODULE
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
So very late to the party here, but I found this thread in my research and wanted to post the solution I came up with
Nginx has a mechanism to post from a worker thread - one that is perhaps running another event loop - to the main thread of the nginx worker process. That is 'ngx_post_event' which lets you post an event handler which will be invoked at some point in the future by the main thread.
You have to choose an event queue to post it on, but whatever you're doing, the answer is certainly &ngx_posted_events.
Here we come to the problem (and a solution): if you do this, your event handler will not get invoked in a timely manner because the main nginx worker process thread is waiting on i/o. It won't even deign to look at the posted events queue until it has some 'real' work to do from i/o.
The solution that's working for me currently (and bear in mind this is only on Linux), is to send the main thread a signal which will wake it up from its epoll_wait reverie so it can get to work on the pipeline coming from the other thread.
So here's what worked:
First grab the id of the worker process main thread and hold it in some process-global state:
// In you 'c' source:
static pthread_t nginx_thread;
// In some code that runs once at nginx startup (in my case the module's preconfiguration step)
Now when to post your callback you use the ngx_post_event call I mentioned earlier, then send a SIGIO signal to the main thread to wake up the epoll_wait operation
The SIGIO event is handled in the main Nginx signal handler - and is ignored (well that's what the log says), but crucially, causes the posted events to be processed immediately.
That's it - and it seems to be working so far... please do point out anything stupid I've done.
To complete the story, you'll need the following #includes:
#include <pthread.h>
#include <signal.h>