I'm trying to find the right words to define two different concepts. After doing a little bit of research on online computer science dictionaries, I think I've found the answer. I just need someone to confirm it. Below, I have the two concepts written down and the words that I think describe them.

Procedure - A set of instructions that breaks away from the main flow of the program. Once the instructions are complete, a value is returned to the point that the procedure was called, and the flow continues from there.

Thread - A set of instructions that DOES NOT break away from the main flow of the program. A thread is run along side the program.

有帮助吗?

解决方案 2

A lot of this stuff is language specific, so I'll try to be as 'layman' and generic as possible.

They aren't necessarily definable in the sense you are using in the question. A Thread is sort of an instance of a procedure that executes concurrently with the rest of the program. They aren't opposites/compliments of each other.

A procedure, in this general sense, sounds like the term for a function, method, subroutine, etc. It is just a block of code that is logically separated, and can be called as needed.

A thread could just be an asynchronous call to a procedure, and it usually shares the same memory space as the calling thread.

Another way of putting it, you have your main thread, which executes from top to bottom, calling any procedures along the way. the called procedures/functions/methods etc are still part of the main thread. You can spawn a new thread for the operating system to manage, that has its own set of procedures/commands to execute but (generally) shares a memory space with the main (or calling) thread.

其他提示

A procedure refers to written code; it's a named thing that does something for you. You can use it as a black box, i.e., you put your arguments in, you get some result back.

A thread is in its best literal sense just that, a line or series of instructions that your computing machinery will follow while executing some code. In that sense, a thread is oblivious to procedures.

TL;DR: a procedure is a piece of code, a thread is something that is executing code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top