DS420 Case study – a reference counting problem 1.0 Clark Elliott Instructor
The Game Multi-player first-person shooter game. Interact with the Avatars of others Magical objects, such as dragons, can be created by the actions of one player, but interact with everyone. Users A,B,…Zn; Machines 1, 2, …n Objects reside on machine where they are created. Users “live” on one machine.
The Dragon Big green dragon with detailed graphics, complex physics, and full history-of- interaction: Expensive object When no one needs the dragon, make her go away to conserve resources
Scenario One (Users) A, B, C are playing the game on machines 1,2,3 B creates dragon. Dragon count is one, for B. A discovers dragon; dragon count is two. B cuts off dragon’s hind foot. A sees dragon with three feet.
One, cont. A gets roasted by dragon, and starts dying. A (on 1) sends message to dragon (on 2) “I am dead” Dragon count is one. A dies. B continues to interact with dragon All is well with scenario one.
Scenario Two (Users) A, B, C are playing the game on machines 1,2,3 B creates dragon. Dragon count is one, for B. A discovers dragon; dragon count is two, for A and B B cuts off dragon’s hind foot. A sees dragon with three feet.
Two, cont. A gets roasted by dragon, starts dying. A (on 1) sends message to dragon (on 2) “I am dead” but message gets lost Dragon count remains two. A dies. B gets killed by a falling anvil, and starts dying. B (on 2) sends message to dragon “I am dead” Dragon count is one. All users are dead, but dragon remains active – ouch!
Solution for two… Before dying, A waits for acknowledgment of death message. Message gets lost. No acknowledgment comes. A resends death message Dragon is decremented; sends ACK A gets ACK, dies.
But, suppose… Second message gets lost? Acknowledgment gets lost, so… –Second message is sent saying “I am dead” –Both first and second messages are received and the dragon is decremented twice. – Dragon count is set to zero, and dragon object is destroyed while B still has a reference to it…”Hey, where’s my dragon?”
Scenario Three (Users) A, B, C are playing the game on machines 1,2,3 B creates dragon. Dragon count is one, for B. A discovers dragon; dragon count is two, for A and B B cuts off dragon’s hind foot. A sees dragon with three feet.
Three – cont. A “tells” C about the dragon (passes the reference), but does not tell the dragon that C knows about the dragon. A and B die, dragon is decremented to zero, dragon object is destroyed to save resources. C says, “Hey, where’s my dragon?”
Some techniques Weighted reference counting, so know about someone being “told” about you. Messages have counters, and sender IDs. Never respond to a message with a lesser ID. Use a reliable message protocol. Do global, independent, garbage collection