From 3b95cd0e3d49a7e9f6d106c0fd0740578cee58b7 Mon Sep 17 00:00:00 2001 From: j2-tulloch <james2.tulloch@live.uwe.ac.uk> Date: Fri, 29 Dec 2023 16:42:21 +0000 Subject: [PATCH] Add new file --- Assignment/BasicContextSwitch.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Assignment/BasicContextSwitch.cpp diff --git a/Assignment/BasicContextSwitch.cpp b/Assignment/BasicContextSwitch.cpp new file mode 100644 index 0000000..25f0ad7 --- /dev/null +++ b/Assignment/BasicContextSwitch.cpp @@ -0,0 +1,17 @@ +#include <iostream> +#include "context.h" // Include the provided context library header + +int main() { + volatile int x = 0; + Context c; + + if (get_context(&c) == 0) { // Save the current context + std::cout << "a message" << std::endl; + + if (x == 0) { + x += 1; + set_context(&c); // Restore the saved context + } + } + return 0; // Return an integer from main +} -- GitLab