Skip to content
Snippets Groups Projects
Commit d4bcab61 authored by Joakim Skogø Langvand's avatar Joakim Skogø Langvand
Browse files

Working eventloop and workerthread

parent 8366bd45
No related branches found
No related tags found
No related merge requests found
# 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
No preview for this file type
......@@ -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(1000));
workerThread.stop();
}
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment