apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Spinetti <m.spine...@pisa.iol.it>
Subject Re: pool threads
Date Mon, 02 Apr 2007 14:35:09 GMT
Seeing the examples in:
http://svn.apache.org/repos/asf/apr/examples/trunk/cat/
I tried to do these changes:
In each thread:

.....
context_1 = (apr_pool_t *)data;
   
if (apr_pool_create(&subpool, context_1) != APR_SUCCESS) {
        apr_thread_exit(thd, exit_ret_val);
}
       
for ( ; ; ) {
    apr_pool_clear(subpool);
    apr_thread_mutex_lock(lock);
   
    <read_an_entry_of_array>

    apr_thread_mutex_unlock(lock);
   
    <elaborates_the entry_of_array>
}
..........
apr_pool_destroy(subpool);  
apr_thread_exit(thd, exit_ret_val);


But  nothing changes.....

Marco


Marco Spinetti ha scritto:
> Hi,
> I have a question about how to use pool in threads.
> I have a main which reads a file and fills an array with about 160000 
> structs.
> Then the mian starts NTHREADS threads with the main pool of main:
>
> apr_thread_create(&tptr[i]->thread_tid, NULL, thread_main, 
> (void*)context, context)
>
> Each thread is an infinite loop:
>
> ..............
>
> for ( ; ; ) {
>        apr_pool_t *subpool;
>              if (apr_pool_create(&subpool, context) != APR_SUCCESS) {
>            return;
>        }
>        apr_pool_clear(subpool);
>        apr_thread_mutex_lock(lock);
>         <read_an_entry_of_array_and_elaborates_it>
>
>       apr_thread_mutex_unlock(lock);
>              apr_pool_destroy(subpool);
> }
>
> A the end the last thread does apr_thread_cond_signal(lock_cond) where 
> the main is locked.
> I'd like to know:
>
> 1) Is it the right way to use subpool for a multi-threading programme?
> 2) In the way I'm using threads after about 200 lines I have a 
> segmentation fault. So I suppose that there is someting wrong: any 
> advice?
>
> Best regards
>
> Marco
>
>
>

Mime
View raw message