If your routine does not affect external variables (without side effects), you can say that it is repeated. . Although not a rule, this is a good recommendation.
If the subroutine uses external variables and saves the state of external variables at the beginning and restores this state at the end, then the subroutine is a retry .
If the subroutine changes external variables and does not save their state in the first place and is interrupted, the state of these external variables can be changed, therefore, when the call returns to its original location in the subroutine, the external variable is not synchronized, which leads to an inconsistent state for the subroutine.
Re-entry functions retain their state (in their local stack, in a thread stack that does not use global variables).
In your case, you get access to the external variable, t , but it returns because the variable is saved and restored at the end of the subroutine.
Usually thread safe means re-entry, but again, there is no rule more than an approximate one. Note. Some locks in Java are returned, so you can recursively call a method and not be blocked by previous calls. (re-entry in this context means that threads can access any section locked with the same lock - a thread can re-enter any block of code for which it already holds a lock)
Solution / Answer:
If you protect t with atoms, you should get a subroutine with a stream. In addition, if you put t in each thread in the stack (make it local), the routine will become thread safe because there is no global data.
Also reentrant! = Recursive; you can also perform ISR in a recursive routine. Essentially, if you call a recursive routine of 2 threads, you will get garbage. To make it thread safe, protect the recursive routine with reentry locks (other locking locks will result in locking / blocking).