Skip to content

Thread Scheduling#43

Merged
Nikil-Shyamsunder merged 49 commits intomainfrom
threading
May 20, 2025
Merged

Thread Scheduling#43
Nikil-Shyamsunder merged 49 commits intomainfrom
threading

Conversation

@Nikil-Shyamsunder
Copy link
Collaborator

@Nikil-Shyamsunder Nikil-Shyamsunder commented Apr 23, 2025

Thread Scheduling Implementation

  1. Thread Management:
    We create a Thread struct to encapsulate transaction state, symbol table, and execution position. We maintain collections of active, next, and inactive threads in the Scheduler struct, which also holds the Evaluator that, in turn, contains the underlying sim. We then implement context switching between threads.

  2. Execution Control:

  • When a fork is reached: A new thread is created from the next available transaction as tracked by the Scheduler. The forking thread continues execution, and the new thread is added to the next execution batch with its next statement to evaluate being the beginning of its transaction (i.e. tr.body). If there are no more available transactions, fork() essentially does nothing.

  • When a step is reached: The thread's execution is paused, the thread is moved to the next execution batch, and Control returns to the scheduler

  • For other statements, normal execution simply continues or if the next statement in the transaction is None, the thread is moved to the inactive_threads vector.

  1. Scheduling Logic:

    • Process active threads until they pause at steps or complete
    • Move completed threads to inactive state
    • Promote next threads to active after a scheduling cycle
  2. Other changes.: diagnostic.rs has a minor change to handle assignment error emissions--just a simple assertion that if the received expressions are from different files, clearly something has gone wrong since an assignment statement cannot span two different files. I created a helper in parser.rs to reduce duplicate parsing code throughout testing modules in the codebase. The *.snap files are just testing files that can be ignored.

  • (i also switched to using my school email as primary for my account, so I switched it in the files)

Testing: Tests are now in the Scheduler for Adder and Multiplier. The simple_if and simple_while tests are ignored for now (still working on building them). the tests in the interpreter are now ignored because they will not work; all tests must now go through the scheduler, and these should be moved to being single-threaded scheduler tests (in a later PR).

@ngernest
Copy link
Contributor

ngernest commented May 20, 2025

Scheduler logic looks good, great work!! Just left a few comments re: style & discussed on Slack how we clean up inactive_threads

@Nikil-Shyamsunder Nikil-Shyamsunder merged commit d64ff58 into main May 20, 2025
10 checks passed
@Nikil-Shyamsunder Nikil-Shyamsunder deleted the threading branch May 20, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants