title: locking between 2 user threads
body: <p>I have a main thread that creates/destroys objects. Let's name the object 'f'.
  Now, every time this object is created it is added to the tailqueue of  another object - say 'mi' . conversely when this object is deleted.
  Now, there is another thread that runs every second, that tries to gather say statistics for this object 'f'. So it basically walks through all the max possible instance of 'mi' (say 2048)and then for each such 'mi', it gathers all the 'f' objects attached to it, sends a cmd down to the lower layer which emits some values corresponding to these objects. Now it must update the corresponding 'f' objects with these values.
  Now the concern is what IF one of these 'f' objects gets deleted by the main thread while this walk is happening every 1s ? 
  Intuitively one would think of having a lock at the 'mi' level that is acquired before beginning the walk and released post the walk /update of all the 'f' objects belonging to a particular instance of 'mi', correct?
  But the only hitch with this is that there could be 10,000's and even millions of 'f' objects tied to this instance of 'mi'.
  The other requirement being that the main thread performance of creating/destroying these 'f' objects should be high i.e at the rate of atleast 10000 objects per second....
  So given that, i'm not sure if it's feasible to have this per 'mi' object lock? Or am i overestimating the side effects of lock contention?
  Any other ideas ?</p>