Tutorial on Threads Programming with Python
0
komentar
Threads play a major role in applications programming today. For example, most Web servers are threaded, as are many Java GUI programs. Here are the major reasons for using threads: • parallel computation: If one has a multiprocessor machine and one’s threading system allows it, threads enable true parallel processing, with the goal being substantial increases in total processing speed. Threading has become the standard approach to programming on such machinese. • parallel I/O: I/O operations are slow relative to CPU speeds. A disk seek, for instance, takes milliseconds, while a machine instruction takes nanoseconds. While waiting for a seek to be done, we are wasting CPU time, when we could be executing literally millions of machine instructions. By putting each one of several I/O operations in a different thread, we can have these operations done in parallel, both with each other and with computation, which does use the CPU. Most Web servers, for example, are threaded. This allows operations for many different clients to be performed in parallel. • asynchronous I/O: Many threaded applications is that they deal with asynchronous actions. In a Web server which is serving many accesses simultaneously, we don’t know which one will complete next. In a GUI program, we may not know whether the user’s next action will be to use the mouse or use the keyboard. By having a separate thread for each action—a separate thread for each Web access, separate threads for mouse and keyboard, etc.—we may be able to write code which is clearer, more convenient and more efficient. • clarity of program code: In some cases, program code may be clearer by writing it in a threaded manner, with each thread handling a separate aspect of the program. • modularity/reusability of program code: Threading may help make code more modular and reusable. Download free Tutorial on Threads Programming with Python here
0 komentar:
Post a Comment