Search code examples
multithreadingmaze

Conceptual: solving maze with multithreading


There are many many maze solving algorithm out there. But just now I came across a description of a quantum computer that states

A quantum computer can try all the paths of a binary maze at one time, and dramatically reduce the time needed to solve a childish problem like a maze

But couldn't we do that right now. I'm no expert in parallel computing but (assuming I can make as many many thread I want) couldn't we just create a new thread every time our program sees a forked path in the maze. This would try out both paths at the same time (right?).

It would be like trial-and-error except we try all the solutions at (almost) the same time.

Prerequisite: very very large number of core at disposal.


Solution

  • New threads are not all actually executed in parallel - you can only execute as many threads in parallel as you have cores (so, on a 4-core computer, only 4 cores can be running code at one time). The OS thread-scheduler switches which thread is running on which core many times a second, so it looks like they are running at the same time, but really they are not.

    If you had enough cores to assign one core to every possible path, then yes, your idea would work. This would actually be possible for smaller mazes on a GPU, which these days can have upwards of 5k+ cores.