Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "call stack" and "thread stack"

Is there a semantic difference between the terms call stack and thread stack, in Java multithreading?

like image 973
Julian A. Avatar asked Jun 30 '15 17:06

Julian A.


People also ask

What is the difference between call stack and stack?

A call stack is a stack data structure that stores information about the active subroutines of a computer program. Where thread stack is what is the private stack of a thread and you know about it. If thread is executing function, that current function call stack is going store into the thread stack .

What is a call stack thread?

The Call Stack window is used to display all currently running threads in a process. It can be used to identify which thread is operational, immediately before program failure occurs.

What is meant by call stack?

A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc.

Is call stack same as memory stack?

They are the same thing. It is also called the execution stack.


2 Answers

Each thread has its own call stack, "call stack" and "thread stack" are the same thing. Calling it a "thread stack" just emphasizes that the call stack is specific to the thread.

Bill Venners calls this the Java stack:

When a new thread is launched, the Java virtual machine creates a new Java stack for the thread. As mentioned earlier, a Java stack stores a thread's state in discrete frames. The Java virtual machine only performs two operations directly on Java Stacks: it pushes and pops frames.

The method that is currently being executed by a thread is the thread's current method. The stack frame for the current method is the current frame. The class in which the current method is defined is called the current class, and the current class's constant pool is the current constant pool. As it executes a method, the Java virtual machine keeps track of the current class and current constant pool. When the virtual machine encounters instructions that operate on data stored in the stack frame, it performs those operations on the current frame.

When a thread invokes a Java method, the virtual machine creates and pushes a new frame onto the thread's Java stack. This new frame then becomes the current frame. As the method executes, it uses the frame to store parameters, local variables, intermediate computations, and other data.

like image 109
Nathan Hughes Avatar answered Oct 04 '22 04:10

Nathan Hughes


A call stack is a stack data structure that stores information about the active subroutines of a computer program.

What you're calling a thread stackis what i assume is the private stack of a thread.

These two things are essentially the same. They are both stack data structures.

A thread's stack is used to store the location of function calls in order to allow return statements to return to the correct location

Since there usually is only one important call stack, it is what people refer to as the stack.

Here is information about the stack.

Here is information about Stack-based memory allocation.

like image 34
Olivier Poulin Avatar answered Oct 04 '22 04:10

Olivier Poulin