sessions and threads

E

Erich Lin

Hi,

I forked off a thread using Thread.new. That thread is supposed to
change a session variable. When I check the session variable in the
thread's function, it had
changed inside the thread. However, this change does not persist after

the thread is finished.

Does anyone know why?

thanks
 
T

Timothy Goddard

Session variable? I take it this is on Rails?

Your original thread is probably ending the request and saving the
session before the other one can finish. You have to make the original
thread wait for the other one to finish using Thread.join.

Threads are very easy to make mistakes with. If you find tracking down
the cause of bugs like this hard, I wouldn't suggest using threads at
all without some further reading.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top