make conses thread safe

@radumereuta please review
Then why not move this function to the context also?
It looks clumsy like this.