You are not logged in.

#1 2007-07-01 16:23:03

Kei
Member
Registered: 2007-04-05
Posts: 88

Thread communication

Hi,

I'm writing a program using the Qt 4.3 toolkit.

My application is using many threads, which want to read/write from/to a single database. I thought of using an extra thread for the database handling to be able to work with a single database connection. But now I wonder how to communicate between the threads, without blocking one of them. Are signals and slots a good idea? Any ideas?

Offline

#2 2007-07-01 19:25:31

tardo
Member
Registered: 2006-07-15
Posts: 526

Re: Thread communication

I guess it depends on what you're doing. Signals/slots is a good way to do it if order doesn't matter. Otherwise I'd wrap those calls with mutexes.

Offline

#3 2007-07-01 19:31:25

Kei
Member
Registered: 2007-04-05
Posts: 88

Re: Thread communication

I don't want the calling threads to be blocked. Their purpose is socket communication and they should be responsive to the network. Telling the database thread to do something isn't the problem but getting the answer to the right thread. Is there something like IPC for threads (in Qt)?

Offline

#4 2007-07-01 19:55:06

tardo
Member
Registered: 2006-07-15
Posts: 526

Re: Thread communication

dbus.

Offline

#5 2007-07-01 20:10:38

Kei
Member
Registered: 2007-04-05
Posts: 88

Re: Thread communication

Can't use DBUS because it ought to be a cross-plattform application.
Anyway, thanks for the help.

Offline

#6 2007-07-01 20:43:43

bboozzoo
Member
From: Poland
Registered: 2006-08-01
Posts: 125

Re: Thread communication

dbus sux for possibly throughput intensive applications, one of standard patterns for such application is queue + mutex + semaphore. With mutex you guard accessing the queue, semaphore is used for signalling object being added to the queue. Thus value of semaphore is = to number of elements queued. Though you would have to pack requests in your own class and do (de)multiplexing.

Offline

#7 2007-07-01 20:44:30

tardo
Member
Registered: 2006-07-15
Posts: 526

Re: Thread communication

The only other way I can think of is a priority queue.

Offline

Board footer

Powered by FluxBB