The File

Submitted by: Submitted by

Views: 154

Words: 261

Pages: 2

Category: Literature

Date Submitted: 07/25/2012 12:33 PM

Report This Essay

Advantages and Drawbacks of Threads(multiprocesses)

Creating a new thread has some distinct advantages over creating a new process in certain circumstances. Theoverhead of creating a new thread is significantly less than that of creating a new process. (Though Linux isparticularly efficient at creating new processes compared to some other operating systems.)Sometimes it is very useful to make a program appear to do two things at once. The classic example is toperform a real−time word count on a document, while still editing the text. One thread can manage the user'sinput and perform editing. The other, which can still see the same document content, can continuously updatea word count variable. The first thread (or even a third one) can use this shared variable to keep the userinformed. A perhaps more realistic example is a multithreaded database server, where an apparent singleprocess serves multiple clients, improving the overall data throughput by servicing some requests while othersare blocked waiting for disk activity. For a database server, this apparent multitasking is quite hard to doefficiently in different processes, because the requirements for locking and data consistency cause thedifferent processes to be very tightly coupled. This can be done much more easily with multiple threads thanmultiple processes.Threads do have drawbacks. Since they are relatively new, they are not as widely available as longerestablished features. Writing multithreaded programs requires very careful thought. The potential forintroducing subtle timing faults, or faults caused by the unintentional sharing of variables, in a multithreadedprogram is considerable. Debugging a multithreaded program is much harder than a single threaded one.