Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Inf3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Marcel Kehrberg
Inf3
Commits
c7935bea
Commit
c7935bea
authored
2 years ago
by
qwertzniki6
Browse files
Options
Downloads
Patches
Plain Diff
refractored to adhere to coding conventions
parent
d281ad98
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Aufgabe3/ConsoleApplication1/Consumer.cs
+1
-1
1 addition, 1 deletion
Aufgabe3/ConsoleApplication1/Consumer.cs
Aufgabe3/ConsoleApplication1/Producer.cs
+6
-1
6 additions, 1 deletion
Aufgabe3/ConsoleApplication1/Producer.cs
with
7 additions
and
2 deletions
Aufgabe3/ConsoleApplication1/Consumer.cs
+
1
−
1
View file @
c7935bea
...
...
@@ -27,7 +27,7 @@ namespace ConsoleApplication1
Console
.
WriteLine
(
"consumer asleep..."
);
Thread
.
Sleep
(
50
);
//if wakeConsumersUp = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next i
n
teration
//if wakeConsumersUp = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next iteration
if
(
_wakeConsumersUp
)
{
Console
.
WriteLine
(
"consumer was woken up"
);
...
...
This diff is collapsed.
Click to expand it.
Aufgabe3/ConsoleApplication1/Producer.cs
+
6
−
1
View file @
c7935bea
...
...
@@ -16,7 +16,7 @@ namespace ConsoleApplication1
public
Producer
(
Buffer
buffer
)
{
_random
=
new
Random
();
this
.
_buffer
=
buffer
;
_buffer
=
buffer
;
}
...
...
@@ -24,17 +24,20 @@ namespace ConsoleApplication1
{
while
(
true
)
{
//if isAsleep = true: method checks if wakeProducersUp has been set to true every 50ms
if
(
_isAsleep
)
{
Console
.
WriteLine
(
"producer asleep..."
);
Thread
.
Sleep
(
50
);
//if wakeProducersUp = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next iteration
if
(
_wakeProducersUp
)
{
Console
.
WriteLine
(
"producer was woken up"
);
_isAsleep
=
false
;
}
}
//if producer isnt asleep: producer gets mutex from buffer, wakes up consumers if buffer is empty and removes cars if producers is not full
else
{
Thread
.
Sleep
(
_random
.
Next
(
500
,
1500
));
...
...
@@ -52,6 +55,7 @@ namespace ConsoleApplication1
_buffer
.
push
(
c
);
Console
.
WriteLine
(
"car "
+
c
.
getThisCarId
()
+
" added"
);
}
//if buffer is full: producers are set to sleep, own instance is set to sleep
else
{
_wakeProducersUp
=
false
;
...
...
@@ -65,6 +69,7 @@ namespace ConsoleApplication1
}
}
//this consumer instance can be woken up by calling this method
public
static
void
WakeUp
()
{
_wakeProducersUp
=
true
;
...
...
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