replaced "in shutdown" flag with a shutdown mutex

avoids possible race conditions during shutdown process