Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Dev

Creating a new thread inside a module

 

 

Apache dev RSS feed   Index | Next | Previous | View Threaded


iroshanmail at gmail

Jun 29, 2009, 9:01 AM

Post #1 of 17 (958 views)
Permalink
Creating a new thread inside a module

Hi All,

I want to open a port to communicate my Apache hhtpd (2.2) with small
software run on a separate machine .Without affecting the httpd how can i
create a new thread to listen to that software.

Also I want to start this thread when the mod_proxy_balancer is initialize
its balancer members(balancer_init).

please helpp me,

thank you,

Iroshan
Under graduate-UCSC
Ari Lanka


mturk at apache

Jun 29, 2009, 9:32 AM

Post #2 of 17 (921 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

h iroshan wrote:
> Hi All,
>
> I want to open a port to communicate my Apache hhtpd (2.2) with small
> software run on a separate machine .Without affecting the httpd how can
> i create a new thread to listen to that software.
>
> Also I want to start this thread when the mod_proxy_balancer is
> initialize its balancer members(balancer_init).
>

Take a look at trunk's mod_watchdog.
It should compile with 2.2 without a problem.
However it requires to be statically compiled so it
can survive the child death.

If that's not feasible, hack it ;)


Regards
--
^(TM)


iroshanmail at gmail

Jun 29, 2009, 10:25 AM

Post #3 of 17 (920 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi Mladen Turk,

Thank you .In Apache 2.2.x trunk there is no such a module mod_watchdog. Is
this is from later version?. Can I compile this in DSO mode with
mod_proxy_balancer.?

Help me

Iroshan.





> Take a look at trunk's mod_watchdog.
> It should compile with 2.2 without a problem.
> However it requires to be statically compiled so it
> can survive the child death.
>
> If that's not feasible, hack it ;)
>
>
> Regards
> --
> ^(TM)
>


iroshanmail at gmail

Jun 29, 2009, 12:47 PM

Post #4 of 17 (917 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi All
Actually I need *to* modify *Apache* and *run* one custom background *thread
*. In addition, my custom modules have *to* be able *to* access the shared
memory and it should be done through the background *thread*. Did anybody do
this before? Is *there* an example I can use as a starting point?

please help me.

Best Regards,
Iroshan
Under graduate
UCSC
Sri Lanka.


mturk at apache

Jun 29, 2009, 1:23 PM

Post #5 of 17 (916 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

h iroshan wrote:
> Hi All
> Actually I need *to* modify *Apache* and *run* one custom background
> *thread*. In addition, my custom modules have *to* be able *to* access
> the shared memory and it should be done through the background *thread*.
> Did anybody do this before? Is *there* an example I can use as a
> starting point?
>
> please help me.
>

I already told you to look at the trunk (mod_watchdog)
http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/core/

It is used to manage the hartbeat module at regular
intervals (you might look at this as well) and it
listens and send data via socket using shared memory extensively
and can manage mod_proxy (well should ;)

Regards
--
^(TM)


wrowe at rowe-clan

Jun 29, 2009, 1:47 PM

Post #6 of 17 (916 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Mladen Turk wrote:
>
> Take a look at trunk's mod_watchdog.
> It should compile with 2.2 without a problem.
> However it requires to be statically compiled so it
> can survive the child death.

*That's* the reason for static?!? See mod_aspdotnet and several
others for how to pin a particular .so module for the lifetime of
the process, instead of per-restart.

No modules in trunk should require static compilation, period.


iroshanmail at gmail

Jun 29, 2009, 3:08 PM

Post #7 of 17 (916 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi Mladen Turk,

Thank you very much. I roughly gone throug the mod_watchdog. I create my
background thread inside the balancer_init method at mod_proxy_balancer
module. But after finished the execution of balancer_init method my thread
also terminate automatically. Do you or any body have idea to avoid this. I
need to run my background thread until the server stop by user.

Best Regards,

Iroshan.


mturk at apache

Jun 29, 2009, 10:09 PM

Post #8 of 17 (896 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

William A. Rowe, Jr. wrote:
>> However it requires to be statically compiled so it
>> can survive the child death.
>
> *That's* the reason for static?!? See mod_aspdotnet and several
> others for how to pin a particular .so module for the lifetime of
> the process, instead of per-restart.
>

Why can't we make some simpler API for such modules instead
hacking the current one when it is obvious that there are
modules that cannot survive the graceful restart?

> No modules in trunk should require static compilation, period.
>

There is a difference between should and must, but seems
to me there's no decent API for that.

Regards
--
^(TM)


wrowe at rowe-clan

Jun 30, 2009, 9:07 AM

Post #9 of 17 (868 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Mladen Turk wrote:
> William A. Rowe, Jr. wrote:
>>> However it requires to be statically compiled so it
>>> can survive the child death.
>>
>> *That's* the reason for static?!? See mod_aspdotnet and several
>> others for how to pin a particular .so module for the lifetime of
>> the process, instead of per-restart.
>>
>
> Why can't we make some simpler API for such modules instead
> hacking the current one when it is obvious that there are
> modules that cannot survive the graceful restart?
>
>> No modules in trunk should require static compilation, period.
>>
>
> There is a difference between should and must, but seems
> to me there's no decent API for that.

mod_aspdotnet is ASL 2.0, and if you want the providence, I'll branch
that fragment from the ASF svn graveyard :) But demarking first from
later restarts using the pool API is really the module author's job.
I suppose I could hack that into mod_example for people looking for
that code. WDYT?

http://svn.apache.org/viewvc/httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp?revision=420045&pathrev=581524

See asp_module_lock - this is entire windows specific; you are right
that we don't have the API to pin the module in an apr-manner. That
really shouldn't be all that hard to do, I'll look. The register_hook
API seems to be the right place to usually do this.

See asp_net_pre/post_config - this is done entirely without statics,
although other module authors figure what's wrong with a static for
exactly this application?


mturk at apache

Jun 30, 2009, 9:50 AM

Post #10 of 17 (868 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

William A. Rowe, Jr. wrote:
> Mladen Turk wrote:
>
> See asp_module_lock - this is entire windows specific;

I see. Nice trick.

> you are right
> that we don't have the API to pin the module in an apr-manner. That
> really shouldn't be all that hard to do, I'll look. The register_hook
> API seems to be the right place to usually do this.
>

I presume.
Perhaps adding something like ap_preloaded_modules table to which
the module can assign itself. But I presume there'll be and issue
with the pool used for LoadModule.


Regards
--
^(TM)


wrowe at rowe-clan

Jun 30, 2009, 10:14 AM

Post #11 of 17 (867 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Mladen Turk wrote:
> Perhaps adding something like ap_preloaded_modules table to which
> the module can assign itself. But I presume there'll be and issue
> with the pool used for LoadModule.

Yes and no...

the loaded module will be "cleaned up"/"unloaded" and reloaded (the
register_hooks are called again).

But the dso will be loaded 2x, the second time against the process
pool, so it won't be "cleaned up"/"unloaded" for real until the
final process teardown.

Interesting Q to me, as the aspdotnet author, is that if I change
the code so that mod_aspdotnet doesn't try to unload itself (see
that asp_net_lock code that is commented out), but let the process
pool cleanup of the mod_aspdotnet module do so, will it still bite
the big one on the way down :) It's an interesting question, so
I'll answer your question by hacking a bit at mod_aspdotnet to get
it ready for such a new API and use the apr_dso loaded against the
process pool, instead of locking the module with the win32 api.


iroshanmail at gmail

Jul 1, 2009, 3:14 AM

Post #12 of 17 (825 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi William and Mladen,

Thanks both of you but i am still struggling with my thread creation. I
create my background thread inside the balancer_init method at
mod_proxy_balancer module. But after finished the execution of balancer_init
method my thread also terminate automatically please help me

Iroshan.


shaniroh at gmail

Jul 1, 2009, 3:23 AM

Post #13 of 17 (821 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi Iroshan and All,

Same problem here. I passed function with infinite while loop when creating
the thread . Thread creation is done inside a function of another module.
But after call the module function thread also terminate. What are the steps
that I have missed here.

Thank you.
Shaniro Herath


On Wed, Jul 1, 2009 at 3:44 PM, h iroshan <iroshanmail[at]gmail.com> wrote:

>
> Hi William and Mladen,
>
> Thanks both of you but i am still struggling with my thread creation. I
> create my background thread inside the balancer_init method at
> mod_proxy_balancer module. But after finished the execution of balancer_init
> method my thread also terminate automatically please help me
>
> Iroshan.
>


mturk at apache

Jul 1, 2009, 3:40 AM

Post #14 of 17 (825 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

shaniro herath wrote:
> Hi Iroshan and All,
>
> Same problem here. I passed function with infinite while loop when
> creating the thread . Thread creation is done inside a function of
> another module. But after call the module function thread also
> terminate. What are the steps that I have missed here.
>

Make sure you guys use the correct pool for thread creation.
The best is to use the child's main pool or to create
the child pool from it.


Regards
--
^(TM)


wrowe at rowe-clan

Jul 1, 2009, 9:14 AM

Post #15 of 17 (813 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

h iroshan wrote:
>
> Hi William and Mladen,
>
> Thanks both of you but i am still struggling with my thread creation. I
> create my background thread inside the balancer_init method at
> mod_proxy_balancer module. But after finished the execution of
> balancer_init method my thread also terminate automatically please help me

Watch which pool you create the thread in. Also your thread can terminate
whenever it wants to return; - it's up to your code to keep itself alive.


shaniroh at gmail

Jul 1, 2009, 4:11 PM

Post #16 of 17 (800 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi,

please can anybody roughly tell me how to register a new thread under the
main child thread pool .It is great help for me.

Shaniro Herath.

On Wed, Jul 1, 2009 at 9:44 PM, William A. Rowe, Jr. <wrowe[at]rowe-clan.net>wrote:

> h iroshan wrote:
> >
> > Hi William and Mladen,
> >
> > Thanks both of you but i am still struggling with my thread creation. I
> > create my background thread inside the balancer_init method at
> > mod_proxy_balancer module. But after finished the execution of
> > balancer_init method my thread also terminate automatically please help
> me
>
> Watch which pool you create the thread in. Also your thread can terminate
> whenever it wants to return; - it's up to your code to keep itself alive.
>


iroshanmail at gmail

Jul 4, 2009, 12:13 PM

Post #17 of 17 (694 views)
Permalink
Re: Creating a new thread inside a module [In reply to]

Hi All,

I am still unable to create a new thread inside the balancer_init function.
Here the way that I tried. But in this way new thread was created and it
terminate after the balancer_init function finish its context. I want run
this new thread for ever until the server stop. Please help me to solve this
problem...


static int balancer_init(apr_pool_t *p, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
apr_status_t rv;
apr_thread_t *tp;
apr_threadattr_t *thd_attr;

rv =apr_thread_create(&tp, thd_attr, doit, ptemp, p);
apr_thread_detach(tp);

//do some thing here
//
//

return 0;
}

here is the function passes for creation new thread


static void* APR_THREAD_FUNC doit(apr_thread_t *thread, void *data)
{
while(1){
printf("ok");
//do some thing here
}
}


Iroshan.

Apache dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.