# Fwd: busywaiting without blocking event loop OR timers

**URL:** <https://www.ruby-forum.com/t/fwd-busywaiting-without-blocking-event-loop-or-timers/211207>\
**Category:** NGINX\
**Created:** [August 29, 2011, 3:36pm UTC](https://www.ruby-forum.com/t/fwd-busywaiting-without-blocking-event-loop-or-timers/211207 "2011-08-29T15:36:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 29, 2011, 3:36pm UTC](https://www.ruby-forum.com/t/fwd-busywaiting-without-blocking-event-loop-or-timers/211207/1 "2011-08-29T15:36:24Z")

</div>

hello everyone,

[this is a crosspost from nginx-devel, which seems awful quiet these  
days …]

i’m working on a module that uses ngx\_event\_connect to connect to a  
3rdparty service and parses its request.  
the answer depends on the request hostname, so now i’m implementing a  
cache in shared memory to cache the responses on a hostname basis.

i’m protecting access to every cache entry using a ngx\_atomic\_t.

now i’d like to prevent multiple concurrent connections from requests  
to the same hostname to the 3rd party service.

i see two ways to solve that:

- busy-wait on ngx\_atomic\_t as long as a request to the service is open
- create an event and wait for it

now, how can i busy-wait on a ngx\_atomic\_t without blocking the  
handling of other requests in the same process?  
(these requests can last up to 10 seconds in worst-case)  
 → can i yield to the event loop while busy-waiting?

can i create events independent of I/O, like timer events?

thanks in advance  
-fin

PS:  
our howto on doing what we’re doing in our module:  
[http://blog.efficientcloud.com/2011/08/24/nginx-upstream/](http://blog.efficientcloud.com/2011/08/24/nginx-upstream/)
