I have created a new thread inside main thread and running while loop until my global variable changed. But if I change the global variable in main thread it is not reflected in new thread. What will be the problem.
Thread.new do
loop do
p "login info"
p logged
mutex.synchronize do
if(!logged)
break
else
begin
#do something
sleep 5
rescue => e
p e
end
end
end
end
I have set logged to false in logout method. But the loop is not breaking
module SessionsHelper
logged =false
# Logs in the given user.
def log_in(user)
session[:user_id] = user[:id]
storeAuthToken(user)
logged=true
end
loggedis local variable for the scope of the thread. You might want to use class/instance variable, but this is definitely a task for aMutex. - Aleksei Matiushkin