Book Image

Parallel Programming with Python

By : Jan Palach, Jan Palach V Cruz da Silva
Book Image

Parallel Programming with Python

By: Jan Palach, Jan Palach V Cruz da Silva

Overview of this book

Table of Contents (16 chapters)
Parallel Programming with Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Defining threads


Threads are different execution lines in a process. Let us picture a program as if it was a hive, and there is a process of collecting pollen inside this hive. This collection process is carried out by several worker bees who work simultaneously in order to solve the problem of lack of pollen. The worker bees play the role of threads, acting inside a process and sharing resources to perform their tasks.

Threads belong to the same process and share the same memory space. Hence, the developer's task is to control and access these areas of memory.

Advantages and disadvantages of using threads

Some advantages and disadvantages have to be taken into account when deciding on the use of threads, and it depends on the language and operating system used to implement a solution.

The advantages of using threads are as follows:

  • The speed of communication of the threads in the same process, data location, and shared information is fast

  • The creation of threads is less costly than the creation...