Skip to content
Snippets Groups Projects
Commit 404d156a authored by t2-akhmetov's avatar t2-akhmetov
Browse files

Update README.md

parent 3d664acc
No related branches found
No related tags found
No related merge requests found
......@@ -106,7 +106,7 @@ clang++ -std=c++11 -o example example_last_pseudo_code.cpp context.o
These commands compile the assembly code for context manipulation and the C++ code, linking them together to create an executable that demonstrates advanced systems programming techniques in action.
### Results
#### Example
![]Screenshot_2024-01-06_at_01.43.09.png
![](Screenshot_2024-01-06_at_01.47.51.png)
#### Unit Testing
## Task 2
......@@ -251,6 +251,7 @@ The main function does following:
- Starts the execution of fibers using `globalScheduler.do_it()`.
### Results
#### Example
![](Screenshot_2024-01-06_at_01.44.02.png)
#### Unit Testing
## Task 3
This solution extends our fiber-based system by introducing the capability for fibers to yield control back to the scheduler before completion. This addition is particularly useful in scenarios like the producer-consumer pattern and other use cases where cooperative multitasking is required. The implementation demonstrates the use of yield in conjunction with get_data to share data between fibers.
......@@ -332,4 +333,33 @@ void do_it() {
- Resuming Fiber Execution: When a fiber that has yielded is resumed, it continues to have access to the shared data. Any changes made to the data by other fibers while it was yielded will be reflected.
```sh
Scheduler globalScheduler;
void foo(Context* currentContext, Context* mainContext) {
Fiber* currentFiber = globalScheduler.getCurrentFiber();
int* sharedData = static_cast<int*>(currentFiber->getSharedData());
std::cout << "Address of sharedData in foo: " << sharedData << std::endl;
std::cout << "Starting fiber 1" << std::endl;
globalScheduler.yield();
std::cout << "after, yield shared Data before the increment: " << *sharedData << std::endl;
*sharedData += 1;
std::cout << "Fiber 1 after increment: " << *sharedData << std::endl;
globalScheduler.fiber_exit(); // Yield control back to the scheduler
}
void goo(Context* currentContext, Context* mainContext) {
Fiber* currentFiber = globalScheduler.getCurrentFiber();
int* sharedData = static_cast<int*>(currentFiber->getSharedData());
std::cout << "Address of sharedData in goo: " << sharedData << std::endl;
std::cout << "shared Data before the increment: " << *sharedData << std::endl;
// globalScheduler.yield();
*sharedData += 1;
std::cout << "Fiber 2: " << *sharedData << std::endl;
globalScheduler.fiber_exit(); // Yield control back to the scheduler
}
```
foo and goo are two fiber functions. foo uses yield to pause its execution, demonstrating how fibers can cooperatively multitask.
main sets up the fibers and shared data, and then starts the fiber execution using `globalScheduler.do_it()`.
**This implementation effectively demonstrates how fibers can be used in a cooperative multitasking environment, especially useful in scenarios where fibers need to yield control back to the scheduler before completing their execution. The addition of yield adds flexibility and enhances the functionality of our fiber-based system.**
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment