use locks on g.waiting in init function