Information Technology Reference
In-Depth Information
critical. For example, allocating 1000 threads with a 16KB stack for each
thread on a machine with 4GB of memory would consume 0.4% of the
machine's memory. Also, most operating systems now have ecient and
scalable threads libraries. For example, where the Linux 2.4 kernel had
poor performance when processes had many threads, Linux 2.6 revamped
the thread system, improving its scalability and absolute performance.
Anecdotal evidence suggests that the performance gap between the two
approach has at least greatly narrowed and that for some applications the
highly-optimized thread management code and synchronous I/O paths
can beat the often less-optimized application code and asynchronous I/O
paths. Performance has probably reached the point that for most appli-
cation other factors (e.g., code simplicity and ease of maintenance) may
be more important than raw performance. If performance is critical for
a particular application, then|as is often the case|tere is no substitute
for careful benchmarking and measurements in making your decision.
Performance: Exploiting multiple processors. The event-driven
approach does not help a program exploit multiple processors. Note, how-
ever, that the event-driven and thread approaches can be combined: a
program that wants to use n processors can have n threads, each of which
uses the event-driven pattern to multiplex multiple I/O-bound tasks on
each thread.
Program structure: Expressing logically concurrent tasks. When-
ever one compares two viable programming styles, one can find strong ad-
vocates for each approach. The situation is no different here, with some
advocates of event-driven programming arguing that the synchronization
required when threads share data makes threads more complex than events
and advocates for threads arguing that threads provide a more natural way
to express the control flow of a program than having to explicitly store a
computation's state in a continuation.
In our opinion, there remain cases where both styles are appropriate, and
we use both in our own programs. That said, it seems to us that for most
I/O-intensive programs, threads are preferable: they are often more natural,
suciently ecient, and able to exploit multiple processors.
4.6
Conclusion and future directions
Concurrency is ubiquitous|many smartphones and the vast majority of servers,
desktops, laptops, and tablets and have 2 or more cores. Multi-threaded pro-
gramming is a skill that every professional programmer needs to master.
Technology trends suggest that concurrent programming will only get more
important over time. After several decades in which computer architects were
Search WWH ::




Custom Search