Make some operations in AsContext atomic
This doesn *not* make access to the class threadsafe though! All retrieved pointers may still be able to change. This is a bit dangerous, so ideally any AsContext class should be initialized once and then never be modified again. In future, in case people really use this in a multithreaded environment, it may be useful to add a sealing mechanism to this class.