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 8518343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:57:12+00:00 2026-06-11T05:57:12+00:00

So in a program I’m writing I use a bi-directional breadth first search to

  • 0

So in a program I’m writing I use a bi-directional breadth first search to search a graph. I do this by running 1 breadth first search in 1 thread, and one in another. Now the search is said to have found the optimal solution when it either an element from the other search is hit, or when the goal is found (which never really happens, but just in case it does for some reason..).

The problem I am running into, is that I need to save this optimal solution to a field, because I need to continue to find all of the solutions, but the field value is getting messed up because both threads hit it at the same time (I think).

Is there a way to block access to the thread who gets there last? I’ve tried using an AtomicReference and its compareAndSet method but that didn’t do the trick. The value still gets messed up….

Btw I’m using java, and for the threads I’m using Callable objects.

  • 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-11T05:57:13+00:00Added an answer on June 11, 2026 at 5:57 am

    Looks like you have a possible Livelock or Race condition that is occuring because of the random order of threads. I’d recommending taking a different approach. (otherwise at some point you will run into NP-Complete).

    The problem I am running into, is that I need to save this optimal solution to a field. because I need to continue to find all of the solutions, but the field value is getting messed up because both threads hit it at the same time (I think).

    There is a way to greatly increase your current technique. You shouldn’t need to look at every solution, take a Greedy Approach and use a Paralleled version of Dijkstra's Shortest Path Algorithm.

    Shortest Path (or in your case Optimal Solution)

    Dijkstra’s Algorithm is a graph search algorithm that solves the single-source shortest path problem for a graph with nonnegative edge path costs, producing a shortest path tree. This algorithm is often used in routing and as a subroutine in other graph algorithms.

    Linear Implementation

    The original algorithm Figure 1. (Source)

    Parallel PDF Algorithm Linear
    (source: iforce.co.nz)

    Java Implementations can be found Here, and Here

    • I think these implementations are based on BSP Trees (but you should get the idea)

    Parallel Implementation

    The parallel algorithm Figure 2. (Source)

    • There are additional ways to speed up the algorithm with recursion, if you want to get classy.

    Parallel PDF Algorithm Atomic
    (source: iforce.co.nz)

    Another idea if you are still having problems, might be to use a different concurrent data structure like Map Reduce or Hadoop instead of using Threads to search through a Binary Tree, to fix your search.

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

Sidebar

Related Questions

This program so far has one purpose, take in two integers(the size of the
First program i'm writing while reading various Haskell tutorials gives me a Kind mis-match
Program that calculates and shows the value of (2 to the 10th power) This
This program builds a dictionary out of a list based on what two index
This program returns: package main import ( flag fmt ) func main() { num_agents
This program runs just fine, but for some reason when I ask for an
The program I'm coding now makes a pretty huge list of data items. Now,
Program I'm making has a simple configuration file looking something like this. @overlays =
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -177935456 (LWP 5483)] 0xf79ff2ca in
My program has two kernels and the second kernel should use the already uploaded

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.