Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:00+00:00 2026-06-14T20:50:00+00:00

This is my first attempt at multithreading after learning about threads (in theory, heh)

  • 0

This is my first attempt at multithreading after learning about threads (in theory, heh) in my OS class at school, and I think the way I’ve gone about doing what I’m trying to do is bad practice/sloppy.

I’m parallelizing a minimax algorithm by spawning a separate thread for each branch of the game on which the algorithm is set to run. The scheduling part of this is a little tricky; as the algorithm deepens iteratively, and I want depth consistency across all the threads.

So, first I have a master thread which spawns a subthread for each available move in the game:

    public void run(){
        // initializes all the threads
        for (AlphaBetaMultiThread t : threadList) {
            t.start();
        }
        try { //This won't ever happen; the subthreads run forever
            evals = 0;
            for (AlphaBetaMultiThread t : threadList) {
                t.join();
                evals += t.evals;
            }
        } catch (Exception e) {
            System.out.println("Error joining threads: " + e);
        }
    }

The thread passes itsself to the constructor so each subthread so that the threads can access the master thread’s maxDepth property and signalDepth methods:

    public synchronized void signalDepth(){
        signals++;
        if (signals % threadList.length() == 0){
            if (verbose)
                System.out.println(toString());
            depth++;
        }
    }

And finally, here’s the subthread evaluation process. Whenever it’s ahead of the rest of the threads, it lowers its own priority, and then yields until all the subthreads have signalled.

public void run() {
    startTime = System.currentTimeMillis();
    while(true){
        if (depth >= master.maxDepth) {
            this.setPriority(4);
            this.yield();
            break;
        } else {
            this.setPriority(5);
        }
        eval = -1*alphabeta(0, infHolder.MIN, infHolder.MAX);
        manager.signalDepth();
        depth += 1;
    }
}

Besides the fact that my implementation seems not to work at all right now (still trying to figure out why), I really feel as if what I’m doing isn’t the standard way of doing things. My intuition is that there are probably all kinds of built-in multithreading libraries that could make my life a lot easier, but I don’t really know what I’m looking for.

Oh, I’m also getting a warning that Thread.destroy() is deprecated (which is how I’m planning on destroying everything after the computer player finally plays its move).

I guess my question is this: what should I be using to manage my subthreads?

edit: Oh, and if there’s stuff I’ve left out that is relevant to my question, feel free to look at my complete code on github: https://github.com/cowpig/MagneticCave
The relevant files are GameThread and AlphaBetaMultiThread.
I apologize for my cluelessness!

Another edit: I want the threads to deepen iteratively forever, until the gamePlayer object (the one creating the master thread) decides it is time to choose a move– at which it will access the list of moves and find the one with the highest evaluation. This means .join() won’t work, unless I create a new set of threads for every depth iteration, but then that would require a lot more overhead (I think) so I don’t really want to have to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:50:01+00:00Added an answer on June 14, 2026 at 8:50 pm

    Your intuition is correct. Java 5 introduced a slew of useful concurrency constructs. One in particular you might want to research is CyclicBarrier. It is a synchronization aid that allows multiple threads to wait on each other to reach a common, barrier point (in your case, that would be the master depth).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first attempt, after reading a lot about DDD, TDD and Repository
This is my first attempt at a plugin but I think I'm missing the
This is my first attempt at creating a Windows service that calls multiple threads.
This is my first attempt on semaphores and threads. I constructed this code from
This is my first attempt to use boost::threads and I have a silly question.
This is my first attempt at a php script after a few weeks of
This is my first real attempt at using multithreading, I want to know how
This is my first attempt at playing with Pandas library after attending Wesley's tutorial
This is my first attempt at creating a custom instance of a class such
This is my first attempt at responsive design, so I'm keeping it simple. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.