[Qt-interest] Socket communication without threads
Predrag Manojlovic
pedjaman at gmail.com
Mon Mar 2 17:49:41 CET 2009
Arnold Krille wrote:
> On Monday 02 March 2009 17:08:37 Predrag Manojlovic wrote:
>> Andreas Pakulat wrote:
>>> On 02.03.09 16:36:27, Predrag Manojlovic wrote:
>>>> Often i hear that threads should be avoided in qt socket applications.
>>>> I'm not sure is that possible always.
>>> Of course its not _always_ possible, but most of the time it is.
>>>> I'm mostly creating applications like TCP chat client/server.
>>>> Questions:
>>>> 2. why is that better?
>>> In general using only 1 thread is better because you avoid all
>>> concurrent-access problems you get when having multiple threads. You
>>> don't need to make sure you're accessing data only from one thread at a
>>> time, debugging is a lot easier, you avoid a lot of possible timing
>>> issues because sometimes one thread runs "faster" than another and causes
>>> a problem.
>> Looks like only reason is concurrent access.
>> I was afraid that I missed something important in my experience :)
>
> "Only concurrent access" _is_ something important. Its actually a lot harder
> than it seems, at first beginners start with no locking at all giving rise to
> all kinds of strange errors that are hard to debug (and when you think you
> mastered them they come back when you run your app on a multi processor
> machine). Then normally the second thing people do is all a lot of hard
> locking where ever data is accessed from multiple threads which mostly results
> in only one thread being active at a time (which is the same as just using the
> main thread). And then you start reading up on the matter and think about it
> and either realize that you don't need multiple threads at all or that you
> have to discriminate between places where hard locking as in "using QMutex" or
> softer locking as in "using QReadWriteLock" or "using QSemaphore" is needed.
> And after that its still a lot of trouble and hard debugging...
>
> So when people start with Qt and want to write "network servers" it is mostly
> right to not use threads at first.
Hi, you got me wrong :)
Reason why i said "Only concurrent access" is because at least 100 times
in list is mentioned that it is not necessary to use threads in socket
I know it is important. I used threads many times in my applications,
and i have 7+ years experience in C/C++ programming.
I'm aware of all possible problems regarding sync.
How can I write network server (multiple connections at same time, like
chat server) without threads? That does not sounds possible.
>
> Have fun,
>
> Arnold
Thank you
Predrag
More information about the Qt-interest-old
mailing list