Archived

This topic is now archived and is closed to further replies.

garywg

What's Multithread Programming?

Recommended Posts

Guest Anonymous Poster
A thread is a path of execution. In Windows, when you start an application, a thread is started to execute that application''s code. That allows multiple applications to appear to be running at the same time since the OS ''timeslices'' the CPU, switching back and forth between threads very quickly.

They are not ''fast'', and they can be a headache. Generally speaking, you shouldn''t use them unless you have to. Server applications are normally where multithreaded programming is found since multiple threads allow servers to work with more than 1 client at a time.

Share this post


Link to post
Share on other sites
One of the benefits of a multithreaded application is that all threads in the application share the same address space. This makes sharing data between the threads much easier and faster than sharing data between applications in different address spaces. (But global sections can be used to make sharing data between applications relatively easy.)

Another one of the benefits of a multithreaded application is that it can take advantage of a multiprocessor computer.

However, one of the primary reasons you should use a multithreaded application is if your threads can operate mostly independent of each other and are required to wait on resources. (i.e. disk I/O) Even on a single CPU system, multithreading can be a great benefit since while one thread is waiting a resource, the application can still continue executing in another thread. For example, early in development of Windows NT, the programmers realized they could improve the performance of copying files by having one thread doing the reading and another thread doing the writing. This change improved the performance by around 30%.

Tim

Share this post


Link to post
Share on other sites