Made socketArray function thread safe