For use in other functions you must declare a global variable. You can use a normal int
outside the traffic function.
But I would call it a major flaw that you have different threads accessing the same variable if the variable isnt
constant for all threads .
It is not clear which thread wins the race for access. So it is better to write an getInteger() and setInteger() function with some syncronization code.
Please read the article
C++11 threads, locks and condition variables for better understanding the pitfalls and solutions.