I have this code, which works as I wanted but I don\'t understand exactly why. Thinking about a stack in C, C++, I\'d guess that the p variable will be on the stack on each call
It's not about closures, here is no any value capturing.
What happening here is that your p parameter is copied by value into the thread's function. Everytime you pass to a function a new value of p is copied to a function.