Added another implementation using lock