# Starting a Thread when Nginx starts

**URL:** <https://www.ruby-forum.com/t/starting-a-thread-when-nginx-starts/210145>\
**Category:** NGINX\
**Created:** [August 1, 2011, 6:56am UTC](https://www.ruby-forum.com/t/starting-a-thread-when-nginx-starts/210145 "2011-08-01T06:56:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 1, 2011, 6:56am UTC](https://www.ruby-forum.com/t/starting-a-thread-when-nginx-starts/210145/1 "2011-08-01T06:56:15Z")

</div>

Hi,  
I am new to Nginx. Have gone through evanmiller blog and nginxguts to  
write my own module. Wrote a hello module which is working fine.  
I extended the hello module and in the http handler, it could start the  
thread. I have used pthread library for this. Now I want to start a  
thread of my own along with nginx and not with a http handler.

1. What modification is required to make it?
2. How to stop the thread when nginx is exiting?
3. Is there a different way of doing it other than pthread for a  
background activity.

Posted at Nginx Forum:

> **[Starting a Thread when Nginx starts](https://forum.nginx.org/read.php?2,213156,213156#msg-213156)**
>
> Hi, I am new to Nginx. Have gone through evanmiller blog and nginxguts to write my own module. Wrote a hello module which is working fine. I extended the hello module and in the http handler, it could start the thread. I have used pthread library for...
