[FASTCGI] libfcgi in multi threaded app

AlannY m at alanny.ru
Wed May 5 09:51:13 EDT 2010


On 03/05/10 21:05, Rob wrote:
>  On 05/03/2010 10:27 AM, AlannY wrote:
> pseudo code for main thread:
> 
>     synchronized_queue_class synchronized_queue  #this is the only
> object that must be visible from all threads
> 
>     function get_fcgi_request( request )
>         request = allocate(sizeof request)
>         FCGX_init_request(request ...)
>         if FCGX_Accept_r(request) is successful
>         then return TRUE
>         else return FALSE
>         endif
>     endfunction
> 
>     while get_fcgi_request( request )
>         synchronized_queue.Put(request)
>     endwhile
> 
> pseudo code for worker threads:
> 
>     while synchronized_queue.Get(request)
>         process(request)
>         deallocate(request)
>     endwhile
> 
> pseudo code for synchronized_queue_class:
> 
>     class synchronized_queue_class:
>         queue internal_queue
>         condition notFull_condition
>         condition notEmpty_condition
>         mutex    monitor
> 
> procedure Put(item):
>             scoped_lock(monitor)
>             while internal_queue.full()
> notFull_condition.wait(monitor)
>             internal_queue.put(item)
>             notEmpty_condition.notify_one()
>         endprocedure
> 
> procedure Get(item):
>             scoped_lock(monitor)
>             while internal_queue.empty:
> notEmpty_condition.wait(monitor)
>             internal_queue.push(item)
>             notFull_condtion.notify_one()
>         endprocedure
> 
>     endclass

I've done my research. And also, I've done my program with your method
from your pseudo-code (nice code).

Seems, that everything works and I can handle requests in parallel.

Several new problems arrived: how to shutdown FCGI socket? My program
want to restart all threads, close connection, open new, create new
threads. But It's not possible to create socket again, because of
"Address already in use" error. I'll continue investigation.

Thanks all.

-- 
   )\._.,--....,'``.
  /,   _.. \   _\  (`._ ,.
 `._.-(,_..'--(,_..'`-.;.'


More information about the FastCGI-developers mailing list