Re: Understanding threading
From: valentin tihomirov (valentin_at_abelectron.com)
Date: 11/29/03
- Next message: Martin James: "Overloaded constructors - safer, easier structure?"
- Previous message: valentin tihomirov: "Re: Understanding threading"
- In reply to: Damien Honeyford: "Understanding threading"
- Next in thread: Brian Cook: "Re: Understanding threading"
- Reply: Brian Cook: "Re: Understanding threading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 16:55:43 +0200
> I'm currently writing a server which uses thread pooling; this is all
working fine at present but I've so far been overly
> careful with locking (currently using critical sections) and I believe
that this will have performance issues later on.
I don't know the difference of mutex vs. CirutSect. Mutexes should be
lighter; may be they are faster as well?
> I've heard a few people say that as long as no writing is performed on a
variable, then any amount of threads can read > it without any locking being
required. Is this correct?
This is the basic concpt of multithreading. However, synchonized access
still should be conserned, because you hardly have an object that need no
updates. There is even a special TMultiReadSingleWrite (or something, never
used myself) in Delphi.
> Also, I read a while back that TThread setting Terminated = True is an
atomic operation, yet at least in my version of > Delphi (rather dated
now -- v4.03) there doesn't appear to be any Interlockedxyz() API's used to
change it's value.
> So how can it be atomic?
May be this is true for all x86 platforms, basically CPUs tend to update
words as a whole, there is no write bit7 in byte 0x0001 instruction.
Furthermore, *Terminated* flag is a single-bit structure and it cannot be
inconsistent in principle.
> Currently I'm using Critical Sections to provide the locking system, but I
realise that they might not be the most
> efficient -- for a high-usage server what would be the best type of
synchronisation to use?
I think events+mutexes as (slightly) more efficient mechanism than messages,
cos messages has their own synch queues.
Multithreading improves performance because of concurrent execution with
expense of synchronization. Synchromnisation in inevitable and it is ALWAYS
consumes time and resources, even in hardware when you cross interclock
domains. Therefore, even advanced programmers avoid multithreading (use
overlapped I/O) if possible. BTW, it is overlapped I/O that is used in place
of multiple threads + blocking I/O in high-performance servers.
- Next message: Martin James: "Overloaded constructors - safer, easier structure?"
- Previous message: valentin tihomirov: "Re: Understanding threading"
- In reply to: Damien Honeyford: "Understanding threading"
- Next in thread: Brian Cook: "Re: Understanding threading"
- Reply: Brian Cook: "Re: Understanding threading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|