Project 1: Optional Task

Fall 2026

The optional task provides an additional challenge for students interested in implementing more functionality in Nachos. We recommend only working on the optional task once you are completely finished with the other parts of the project. As a challenge problem, we do not provide sample tests and can only answer clarification questions about the specification.

Futures

Web programming proliferated an asynchronous programming style, where performing some action triggers an asynchronous operation that takes an unknown amount of time (e.g., downloading an image from a Web server). An early design pattern for a program to know when the operation finishes is to associate a callback with the operation: when the operation finishes, the callback is invoked.

Modern languages have added features to streamline writing programs using asynchronous operations (e.g., Promises in JavaScript, Futures in Java, C++, and Rust). In this problem, you will implement a simple version of Futures. When instantiating a new Future, programs pass in a function to be invoked asynchronously (for simplicity, assume the function takes no arguments and returns an int). At any point, a program may invoke get on the Future to obtain the return value of the function. If the function has not completed when get is invoked, then the caller is blocked. If the function has completed, then get returns the result of the function. Note that get may be called any number of times (potentially by multiple threads), and it should always return the same value.

Implement the Future class using a Nachos KThread to execute the function asynchronously. Happily, the Future class now enables us to effectively have KThreads return a result.