RiedleroD/BASAV

Add pseudo- multithreading

RiedleroD opened this issue · 0 comments

Should be somewhat possible to implement something like this with a few new actions:

  • NEW_THREAD(*args,**kwargs)
    Creates a new thread and supplies the specified *args and **kwargs to the thread constructor
  • LOCK_LOCK(n)
    waits until the nth lock is released & locks it
  • RELEASE_LOCK(n)
    releases the nth lock
  • WAIT_LOCK(n)
    waits until the nth lock is released

and Algorithm callbacks:

  • new_thread(*args,**kwargs):
    (algorithms may define it without *args and **kwargs)
    gets called when NEW_THREAD is yielded, and should return a new generator that inherits BaseAlgorithm.
    (this is a classmethod)

Threads should be handled like separate algorithms, where each non-waiting thread gets called equally often than the others. This should be implemented by calling them 'in a circle'. If an algorithm yields to wait, the member thread.lock should be set to the number that is specified. Every time a thread should be called, its member thread.lock has to be read & checked. If the lock is currently locked, the thread should not be called & it should continue with the next one. If a full round has been completed without a thread being called, the algorithm should be stopped and the user should be notified (per print) that a deadlock has occured.