Report as inappropriate.
Retrieve high scores without blocking, in a "thread safe" way.
I put "thread safe" in quotes for a couple of reasons:
- It's not just a simple library example that takes care of all the nasty stuff for you, you still have to manage the storage yourself in a thread-safe way. It's just the retrieval of the scores (in the ScoreBoard) class that hides the threading side of things. In short, you still have to know what you're doing around threads to take this example and use it safely.
- It's "thread safe" in the sense that the example guarantees only one thread touches the UserInfo class at any one time, and all other work happens on the simulation thread (so no Actors, etc. are being manipulated in other threads.) It's not, strictly speaking thread safe in the sense that the thread which touches the UserInfo class *isn't* the simulation thread. While I can't ever see that being a problem in practice, it's worth bearing in mind.
It really is a big trade off. You can use this approach if you really don't want the (minor) pause when the UserInfo class is working, but in doing so you introduce a lot more complexity and the potential for a lot more to go wrong if you're not very careful!
In terms of the scores - completely random. The ball simply moves to the other side of the screen and back, then the process of storing / displaying the scores is started. When the ball changes to a bomb, that's when the scoring threads are working in the background.
2581 views / 300 in the last 7 days
1 vote | 0 in the last 7 days
Want to leave a comment? You must first log in.