What is a thread?

El_Fraggy

n00b
Joined
Jan 29, 2004
Messages
5
Hey, im just revising for one of my exams and was just wondering what a thread is and also what are the differences between a thread and a process.

Any help would be much appreciated,

Thank you very much:D
 
Originally posted by El_Fraggy
Hey, im just revising for one of my exams and was just wondering what a thread is and also what are the differences between a thread and a process.

Any help would be much appreciated,

Thank you very much:D
Threads and processes are very similar. A thread is like a lightweight process -- some context information which must be saved in the process control block on each context change does not have to be saved when changing thread contexts. Processes typically have their own protected memory space, wheras threads share the same memory.

Context changes are faster with threads, because there's less to do. You have less information to save, and you don't have to muck around with page tables.

That should at least get you started... I'd suggest re-reading the sections in your book(s) which cover processes and threads, with the above differences in mind. I'm sure there's a lot more that I've left out. :D
 
You're very welcome. Welcome to the forums:

THREAD: (def)
A sequence of a program which runs a certain function within a program. As an application runs, it spawns off functions within the program as a thread. These threads allow programs to break down their processing into smaller "chunks."

For example, your mail program may need to contact the server to check for new mail, that function could be a thread. Some operating systems can run multiple threads at one time, allowing for fast execution of an application.

In Windows, you can use the task manager to view "processes" which are collection of threads.
 
thanx peeps,

much appreciated, just wish me luck for my exam in the morning!!

going to do an all nighter :D
 
One other point I guess I left out before... Threads (typically -- always as far as I know but I'm not 100% on this) run inside of a process. Processes on Unix and Windows can belong to different users. All of the threads in a given process (usually) run in the same security context.

Threads share everything except (This list is adapted from one in Steven's "UNIX Network Programming: Volume 1"):
  • "registers"
  • stack
  • thread ID
  • errno
  • signal mask
  • thread priority
I put the quotes around "registers" because there really is only one set of registers, which are part of the hardware in the CPU. On every context change, the contents of all registers must be stored in memory, and the register contents of the next process must be restored. This gives the illusion of each process, and each thread having its own private set of registers.
 
just thought i'd say thank you for the replies i have had and that i just took the exam and the questions with threads and processes i most certainly got right.

cheers guys :D

now its time to get some sleep:eek:
 
Good to hear that you got those questions -- congrats!

What book are you using for the class?
 
Andrew S. Tanenbaum, Modern Operating Systems

Well, its the one we are meant to be using but I havent bought it yet :p
 
Back
Top