Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ASP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
j2-tulloch
ASP
Commits
7183406c
Commit
7183406c
authored
1 year ago
by
j2-tulloch
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
5f9bb0f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment/Task 2/main.cpp
+41
-0
41 additions, 0 deletions
Assignment/Task 2/main.cpp
with
41 additions
and
0 deletions
Assignment/Task 2/main.cpp
0 → 100644
+
41
−
0
View file @
7183406c
#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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment