threading troubles

Hi all!

Im expiriencing some thread related problems with an applet game Im writing…

I have 3 threads running: the game thread itself, a keepalive thread that posts a message to the server each x seconds and an sound thread that pulls my musicplayer for sampledata frequently.

I found out that the applet’s paint seems to get called by the browser, in certain situations the browser seems to call the applet’s repaint in some sort of loop. This caused my sound thread to get too little priority which caused sound stutter. I was able do disable the browser repaints by setting: setIgnoreRepaint(true).

But I had to modify my run method too. Using the sleep() function halved my framerate, thread.yield() resulted in good fps but somehow i loose control after x secs and the whole applet goes beserk. When I call Thread.join(1) it seems to work ok, but I think thats not the proper way of doing this. I thought that join(1) waits 1 ms to kill the thread which doesn’t seems to be what i want. Also on slower systems the game thread seems to pause very shortly when I play an audioclip.

How should I implement the thread.yield() properly? It somehow just looses control after a variable period of time…

Thanks!

Thijs

Can you describe what you mena by “loses control”?
Exaclty what happens?

Typically in any multi-threaded code, if a sleep ‘fixes’ your problem then it means you have a race condition somewhere…

I have one sound thread which constantly pulls my music player for sample data and feeds it to the javasound driver. The other thread is the game itself which basicly calls a repaint() followed by a thread.join(1) but which should be a thread.yield i think.

When using thread.yield() :
The game plays ok for about 30 seconds, after that just goes beserk; does not respond to input and it will stutter (sound & graphics). If i press fx the left key, it will respond with a lag of x seconds and seems to kep excecuting that…

When I use thread.join(1) it works ok, but im sure thats not the right way of doing what i want.

a sleep(>20) obviously halfs the framerate but works ok too…

I think we’re gonna need to see some of your code to get an idea of why that’s happening. I personally can’t think of a reason that your game should be blowing up on you like that. Show some code and hopefully we can help you track down the problem.