Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Network Programming assignment 4
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
Container 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
Joakim Skogø Langvand
Network Programming assignment 4
Commits
d4bcab61
Commit
d4bcab61
authored
4 years ago
by
Joakim Skogø Langvand
Browse files
Options
Downloads
Patches
Plain Diff
Working eventloop and workerthread
parent
8366bd45
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+116
-0
116 additions, 0 deletions
.gitignore
build/eventloop
+0
-0
0 additions, 0 deletions
build/eventloop
main.cpp
+2
-1
2 additions, 1 deletion
main.cpp
workers.cpp
+8
-3
8 additions, 3 deletions
workers.cpp
with
126 additions
and
4 deletions
.gitignore
0 → 100644
+
116
−
0
View file @
d4bcab61
# Created by https://www.toptal.com/developers/gitignore/api/c++,cmake,emacs
# Edit at https://www.toptal.com/developers/gitignore?templates=c++,cmake,emacs
### C++ ###
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Linker files
*.ilk
# Debugger Files
*.pdb
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
cmake-build-debug
### CMake Patch ###
# External projects
*-prefix/
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
ltximg/**
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# network security
/network-security.data
# End of https://www.toptal.com/developers/gitignore/api/c++,cmake,emacs
This diff is collapsed.
Click to expand it.
build/eventloop
+
0
−
0
View file @
d4bcab61
No preview for this file type
This diff is collapsed.
Click to expand it.
main.cpp
+
2
−
1
View file @
d4bcab61
...
...
@@ -15,6 +15,7 @@ auto helloWorld = [](int i) {
void
workersTest
()
{
jlworkers
::
Workers
workerThread
(
16
);
std
::
mutex
printMutex
;
workerThread
.
post
([]()
{
std
::
cout
<<
"Hello, World!
\n
"
;
...
...
@@ -34,7 +35,7 @@ void workersTest() {
<<
", thread id "
<<
std
::
this_thread
::
get_id
()
<<
"
\n
"
;
});
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
0
));
workerThread
.
stop
();
}
...
...
This diff is collapsed.
Click to expand it.
workers.cpp
+
8
−
3
View file @
d4bcab61
...
...
@@ -36,8 +36,8 @@ namespace jlworkers {
m_runnerThread
=
std
::
thread
([
this
]
{
while
(
m_running
)
{
std
::
cout
<<
"Queue: "
<<
m_queue
.
size
()
<<
"
\n
"
;
if
(
!
m_queue
.
empty
())
{
if
(
m_runningThreadCount
<
m_maxThreadCount
)
{
//while
(!m_queue.empty()) {
while
(
m_runningThreadCount
<
m_maxThreadCount
&&
!
m_queue
.
empty
()
)
{
// Fetch next task in queue
auto
f
=
*
m_queue
.
begin
();
// Keep track of running threads
...
...
@@ -51,7 +51,7 @@ namespace jlworkers {
m_runningCondition
.
notify_all
();
}));
}
}
//
}
// Wait for any status updates
std
::
cout
<<
"Create lock and wait for update
\n
"
;
...
...
@@ -69,6 +69,11 @@ namespace jlworkers {
*/
std
::
cout
<<
"Stop runner thread; locking mutex
\n
"
;
while
(
!
m_queue
.
empty
())
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
m_runningMutex
);
m_runningCondition
.
wait
(
lock
);
}
// Scope this to avoid deadlock
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
m_runningMutex
);
...
...
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