guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pool of threads with one producer and several consumers


From: Amirouche Boubekki
Subject: Re: Pool of threads with one producer and several consumers
Date: Sun, 17 Jul 2016 15:13:54 +0200
User-agent: Roundcube Webmail/1.1.2

On 2016-07-17 13:51, Amirouche Boubekki wrote:
Héllo guilers!

This is more like system programming question, but hopefully someone
will enlighten me.

I'd like to create a pool of thread with one producer and several
consumers. This needs comes from the need to make my database server
multithread. The flow of the program I imagine is the following:

1. The client application need to do a query against the database

2. The client open a connection against the server

3. The client send the query

4. The server's main thread accept a new connection

5. The server dispatch the connection to consumer threads

6. The consumer thread reads the query, execute it, returns the result
   and close the connection

The point I'm trying to solve is the point 5, when the server main
thread receive a new connection it must send the new connection to one
of the consumer.

TIL: multiple threads can accept incoming connection from the same socket, the system will make sure that only one thread accepts an incoming connection.
Otherwise said, I don't need to create a producer/consumer machinery.

I did not find a specific reference about this. It's written (somewhere)
that accept is threadsafe in POSIX, but so is select and it wakes up multiple
threads... so magic happens here for greater good.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]