This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

mjrb4
mjrb4 presents ...

2012/9/17

ConcurrentScore

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.

3311 views / 33 in the last 7 days

1 vote | 0 in the last 7 days

Tags: demo with-source

Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Mon Sep 17 15:06:40 UTC 2012
Super_HippoSuper_Hippo

2014/8/6

Hey, do you still have the source code for this and can upload it? I still have no idea how to use those mysterious threads and this scenario looks like an easy example.

Want to leave a comment? You must first log in.

Who likes this?

SPower