• Post Reply Bookmark Topic Watch Topic
  • New Topic

How should I design my threads?

 
Jim Venolia
Ranch Hand
Posts: 248
2
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing the game of Life. The main loop is

Board is a boolean[2][XSIZE][YSIZE].

I want to put nextGeneration in it's own thread. How do I synchronize my threads? In a multiprocess system I'd just use a message queue or semaphore, but I'm not seeing any way to do that.

Comments on how to design this are also welcome.

Background. Been writing embedded device drivers for 30 years. Good at C/C++, just learning Java (life is usually the first thing I write when learning a new language). Very good dealing with multiple tasks/processes, not much thread experience. Some OOP experience, enough to make me dangerous but not actually good at it.
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Venolia wrote:In a multiprocess system I'd just use a message queue or semaphore, but I'm not seeing any way to do that.


Yep, that's exactly what you should do in Java too. Check out the classes in package java.util.concurrent and you'll find one called Semaphore and a variety of Queues.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!