Is thread in operating system = thread function in programming languages? I'm new to Operating System, just learnt about process and now is about to learn about threads. From what I understand,


a program is an executable file, program code
a process is a program in execution
a thread is part of a process
in a process, there might be multiple threads. e.g. MS Word
in a programming code, there is the main function and there're might be other functions also
because there is only one main function, usually the program would just run from top of the main function to down.




My question are:

Q1. Is thread in operating system = function in programming language?

Q2. Is function in programming language = thread function in
programming language?

Q3. Is thread in operating system = thread function in programming language?

Q4. Thread function allows multiple functions to be performed simultaneously, like having multiple main functions. Is this correct?

Q5. Where is thread written in operating system/ programming language? 

I appreciate it greatly if somebody can explain these in simple terms, and examples from analogy or simple programming languages (C/C++/java).



EDIT:
What I mean by thread function (I'm not sure if this is a correct term) is like,


pthread.h in POSIX thread programming
thr_create, thr_join etc in Thread Functions in Solaris and Windows 9x/NT
CreateThread (included in windows.h?) in Create Threads using C in Windows.




I guess that "thread function" = "thread".

If so, then, from David's answer, 


  Q2. Is function in programming language = thread function in programming language?



no.


And from a Q&amp;A in Quora here, it says that


  Q: What is the difference between a thread in a programming language, like Java or Python, and a Linux thread?
  
  A: There is no difference; it is the same word with the same meaning (as opposed to one word that's overloaded to mean multiple things). The operating system will execute threads in parallel as requested by the software that creates the threads.


So, I guess that the answer for my third question, 


  Q3. Is thread in operating system = thread function in programming language?



yes.


And, from POSIX Thread


  Initially, your main() program comprises a single, default thread. All other threads must be explicitly created by the programmer


so I guess the answer for


  Q4. Thread function allows multiple functions to be performed simultaneously, like having multiple main functions. Is this correct?



I think yes.




Q6. Will the program not be able to do multithreading if it doesn't include these thread functions?


I think yes. 


Although I'm not sure how it is included/written in programming code that doesn't explicitly use thread functions directly like CreateThread etc., which is my fifth question.



For example, in Tetris code in C, I didn't see any "thread" word inside the code. Instead, it uses conio.h, which is from wikipedia


  conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C, nor is it defined by POSIX.


Q7. So does this mean this particular programming code in Tetris code in C is single-threaded only? 

Q8. Is it by including windows.h, a programming code can perform multithreading?



Please correct me if I'm mistaken.

The remaining questions are Q5, Q7, Q8.
because there is only one main function, usually the program would just run from top of the main function to down.


That's a long way from being the case. Loops, conditional statements and function calls mean that the control flow of any non-trivial program is much more complex than just running from the top of main() to the bottom.


  
  Is thread in operating system = function in programming language?
  


No. A thread is, essentially, a subprocess. A process may have several threads, and each of these threads executes semi-independently while sharing some common information. A function, on the other hand, is typically a somewhat self-contained unit of work.

An analogy might be that a process is like a company (there can be many different processes, they're kept separate from each other but they can arrange to cooperate with each other in various ways, governed by the law of the country they're in), a thread is like an employee of a company (employees share access to the company's resources and cooperate closely under rules defined by the company) and a function is a specific task that might be performed by an employee (making coffee, typing a letter, attaching a door to a car, etc.)


  
  Is function in programming language = thread function in programming language?
  Is thread in operating system = thread function in programming language?
  


The things you're calling "thread functions" are just programming language libraries that access the operating system's interface for creating and managing threads


  
  Thread function allows multiple functions to be performed simultaneously, like having multiple main functions. Is this correct?
  


Well, threads allow multiple functions to be performed simultaneously. main() is just the entry point to the program as a whole: it's the place where execution starts.


  
  Where is thread written in operating system/ programming language?
  


I'm not sure what you mean by this but it's going to depend on the OS and programming language in question.


  
  Will the program not be able to do multithreading if it doesn't include these thread functions?
  


A program will need some way of telling the operating system to make a new thread. In practical terms, using a library that somebody has already written is going to be more convenient than trying to manage the interaction with the operating system yourself.