Changed samples buffer to be thread-safe.