5

This is how I see threads. Please do correct me if I'm wrong:

A thread is a part of a process that runs a sequence of program code. There can be many threads within a process that run different parts of a program (one thread manages keyboard input, one manages auto-saving, one manages printing etc.). The process allocates resources while the thread(s) are responsible for getting tasks executed by being scheduled for CPU time.

My question is:

Are threads always bound to their own process or can they exchange resources with other threads outside of their process?

Raphael
  • 73,212
  • 30
  • 182
  • 400
user51172
  • 51
  • 1

1 Answers1

1

Threads are used to handle tasks simultaneously. For example, you keep your computation running in a thread, while another thread is waiting for keyboard input.

Threads inherit the privileges of the process they run in.
If the parent process is authorized to access another process's resources than the thread can do this.
The operating system assigns the process privileges when starting that process.

Whether your threads can obtain resources or not depends on the implementation of threads in your operating systems. In Linux, with some languages such as C, your threads are able to share memory with other processes, and even threads can create other threads. Basically, threads' access to memory is the same as your process. So, threads can create a shared memory with another process and keep communicating with other processes via shared memory space.

Johan
  • 1,090
  • 10
  • 27
orezvani
  • 1,944
  • 15
  • 20