Unix Programming - thread pool

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2006 > thread pool





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author thread pool
somashekhar.sonnagi@gmail.com

2006-04-02, 7:41 pm

I am writing one server, where i want to create thread pool (about 10
threads) before accept the connection. whenever i get request from any
client assign already created thread from pool to this client and
service the request.

i already written program which handles the request from client by
accepting the connection and creating new thread and assigning the
client request to it.but it need more performance then this.

Is there any way first create a thread add it in pool and later run
that thread whenever i need. instead while creating time assigning
the function to it to run.

waiting for suggestions
thanx and regards
++Somu

Ulrich Eckhardt

2006-04-02, 7:41 pm

somashekhar.sonnagi@gmail.com wrote:
> Is there any way first create a thread add it in pool and later run
> that thread whenever i need. instead while creating time assigning
> the function to it to run.


The idea of a thread pool is that you have a set of threads waiting in
standby for a task to perform. Just use a kind of queue and have each
thread wait for an element to become available.

Uli

--
http://www.erlenstar.demon.co.uk/unix/
clayne

2006-04-02, 7:41 pm

somashekhar.sonnagi@gmail.com wrote:
> I am writing one server, where i want to create thread pool (about 10
> threads) before accept the connection. whenever i get request from any
> client assign already created thread from pool to this client and
> service the request.
>
> i already written program which handles the request from client by
> accepting the connection and creating new thread and assigning the
> client request to it.but it need more performance then this.
>
> Is there any way first create a thread add it in pool and later run
> that thread whenever i need. instead while creating time assigning
> the function to it to run.


What's the difference? If you want a thread pool of listeners waiting
to accept new connections, just create 10 threads with a start function
that eventually calls accept() on a socket that has already been passed
to listen(). Pass said socket fd to the start function via thread arg,
and within the start function, call accept in blocking mode contained
in a while (1) loop. Done.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com