Can I save a value out of my currernt thread?

235 views Asked by At

I met some confusions when writing a C program.

My scenario has 2 thread but they run serial, so at one time there's single thread. I want to save a parameter in my first thread and I want to get it in my second thread. (pthread here)

So is there anyway to realize this? Public static parameter will be recycled when the thread ends because it belongs to the current thread. I want to save a value or pointer in current process instead of thread so that I can attach it in my next thread...

Is there any possible way to realize this?

Thanks so much!

1

There are 1 answers

0
Matthias On

Threads share the memory. Use a variable (either global, local to the creating thread, or at the heap) and pass a pointer to both threads that points to that very variable.