Skip to content
Snippets Groups Projects
Commit 7183406c authored by j2-tulloch's avatar j2-tulloch :speech_balloon:
Browse files

Upload New File

parent 5f9bb0f4
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include "scheduler.h"
scheduler s;
int shared_data = 10;
void func1(void* arg) {
std::cout << "Entering Fiber1" << std::endl;
std::cout << "fiber 1 address: " << arg << std::endl;
std::cout << "fiber 1: " << shared_data << std::endl;
shared_data++;
s.fiber_exit(); // Exit the fiber
std::cout << "Exit of Fiber1" << std::endl;
}
void func2(void* arg) {
std::cout << "fiber 2 address: " << arg << std::endl;
std::cout << "fiber 2: " << shared_data << std::endl; // This should now print 11
s.fiber_exit(); // Exit the fiber
}
int main() {
try {
std::cout << " Starting funcs" << std::endl;
fiber f1(&func1, nullptr);
std::cout << "Shared data:" << shared_data << std::endl;
std::cout << "Between" << std::endl;
fiber f2(&func2, nullptr);
std::cout <<"Funcs Done" << std::endl;
s.spawn(&f1);
s.spawn(&f2);
std::cout <<"Spawning" << std::endl;
s.do_it(); // Execute the fibers
std::cout << "HELLO" <<std::endl;
} catch (const std::exception& e) {
std::cerr << "Exception Caught:" <<e.what() <<std::endl;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment