Lets assume the following situation:
function add_to_list
{
thelist="$thelist $$"
}
for i in $(seq 1 100); do
add_to_list&
done
wait
echo "The list: $thelist"
This obviously does not work as it should, because the threads are accessing the same variable - how should it be done properly