Question: My question is regarding threads in general(ex: in Java).

The problem : when a thread is being in (Runnable - state) - i.e: it is executing, and it is giving an instruction (say by invoking the method `addOneToX(int x)`), is it possible for the thread to quit or stop its work before finishing the instruction but after it has started executing it. in other words, most of instructions in high-level languages are decoded into the machine-specific language and decomposed to a number of machine-cycles (clock-cycles) in the CPU. So I guess it is clear, accordingly:

**1>** What is the minimum time given to a thread to be in the Runnable state?

**2>** How does the thread save its state so that it comes to it later? (i.e: when it quits Runnable state and comes back to it later to continue from where it stopped)

Answer: 
There is no guaranteed minimum time.

The scheduler decides what the time slice will be. Usually you could expect anything from fractions of a millisecond to about 100ms. But often this value will by dynamic. Also, a thread might even encounter an extreme like running only one instruction which happens to be I/O, upon which the thread blocks and is pushed out of CPU.

The high-level language instructions are eventually translated into (possibly) multiple CPU instructions. The CPU instruction is the atomic part that will be executed without interruption, other than that the program may be interrupted at any place between two instructions, even in the middle of a high-level language command. Note that there are some specific CPU instructions (like atomic get-and-set or get-and-increase) that can be used for thread synchronization.

The basic (much simplified) idea of storing the thread's state is: store the registers in RAM and store the pointer to current instruction.
> 
> What is the minimum time given to a thread to be in the Runnable state?
> 
> 
> 

Most practical Java implementations use *native* threads: That is, they allow the operating system to take care of the details of scheduling threads. Most modern operating systems offer a choice of various thread-scheduling algorithms, and most algorithms offer a number of configurable parameters. There is no single answer to your question.

Almost certainly, it will be less than one second. Quite likely less than 100 milliseconds. Other than that, it's hard to say.

> 
> How does the thread save its state so that it comes to it later?
> 
> 
> 

The state of a thread (in most programming languages, Java included) consists of its *call stack*, and it's CPU registers. The CPU registers include one that points to the top of the call stack, one that points to the current instruction, and usually others.

When it's time to switch threads, the OS interrupts the processor (an interrupt basically forces an immediate function call) and the interrupt handler routine saves all of the CPU registers to a memory location that is reserved for the current thread. Then it restores the registers for some other thread and basically "returns" to wherever that other thread was interrupted.