Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Fix macOS build compatibility by jodyhagins · Pull Request #4 · buildingcpp/concurrency · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,12 +68,34 @@ if (WORK_CONTRACT_BUILD_BENCHMARK)
fetch_dependency("https://github.com/fmtlib/fmt.git;master")
fetch_dependency("https://github.com/cameron314/concurrentqueue.git;master")
#fetch_dependency("https://github.com/boostorg/lockfree.git;master")
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")

# Handle lockfree_mpmc_queue - on non-Linux platforms, just fetch headers to avoid build issues
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# On Linux, use normal fetch_dependency which builds the library
fetch_dependency("https://github.com/erez-strauss/lockfree_mpmc_queue.git;master")
else()
# On other platforms (macOS, Windows), only fetch headers - building fails due to x86 intrinsics
if ("${_lockfree_mpmc_queue_src_path}" STREQUAL "")
message("Fetching Content: lockfree_mpmc_queue (headers only)")
FetchContent_Declare(
lockfree_mpmc_queue
GIT_REPOSITORY "https://github.com/erez-strauss/lockfree_mpmc_queue.git"
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-build"
)
FetchContent_Populate(lockfree_mpmc_queue)
# Don't add_subdirectory to avoid build issues on non-Linux platforms
set(_lockfree_mpmc_queue_src_path ${CMAKE_BINARY_DIR}/lockfree_mpmc_queue-src CACHE STRING "")
endif()
endif()

fetch_dependency("https://github.com/google/googletest.git;main")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(TBB_BUILD_TESTS OFF)
set(TBB_BUILD_SHARED OFF)
set(TBB_BUILD_STATIC ON)
set(TBB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(TBB_BUILD_STATIC ON CACHE BOOL "" FORCE)
fetch_dependency("https://github.com/wjakob/tbb.git;master")
endif(WORK_CONTRACT_BUILD_BENCHMARK)

Expand Down
8 changes: 6 additions & 2 deletions src/executable/1_basic_contract_execution/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(1_basic_contract_execution PUBLIC ${_work_contract_di
target_link_libraries(1_basic_contract_execution
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(1_basic_contract_execution PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/1_basic_contract_execution/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
// Create a work contract group
bcpp::work_contract_group group;

// Start worker thread to process scheduled work contracts
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -32,4 +32,4 @@ int main()
worker.join();

return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/2_recurrent_scheduling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(2_recurrent_scheduling PUBLIC ${_work_contract_dir}/s
target_link_libraries(2_recurrent_scheduling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(2_recurrent_scheduling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/2_recurrent_scheduling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -25,4 +25,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/3_custom_cleanup/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(3_custom_cleanup PUBLIC ${_work_contract_dir}/src ${_
target_link_libraries(3_custom_cleanup
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(3_custom_cleanup PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/3_custom_cleanup/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand All@@ -28,4 +28,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/4_blocking_mode/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(4_blocking_mode PUBLIC ${_work_contract_dir}/src ${_i
target_link_libraries(4_blocking_mode
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(4_blocking_mode PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/4_blocking_mode/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::blocking_work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract(/*std::chrono::seconds(1)*/); // use infinite wait - note: we could use wait with timeout here as well
Expand DownExpand Up@@ -39,4 +39,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/5_exception_handling/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(5_exception_handling PUBLIC ${_work_contract_dir}/src
target_link_libraries(5_exception_handling
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(5_exception_handling PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/5_exception_handling/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
#include <library/work_contract.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -33,4 +33,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
8 changes: 6 additions & 2 deletions src/executable/6_data_ingress/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,10 @@ target_include_directories(6_data_ingress PUBLIC ${_work_contract_dir}/src ${_in
target_link_libraries(6_data_ingress
PRIVATE
pthread
rt
work_contract
)
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(6_data_ingress PRIVATE rt)
endif()
6 changes: 3 additions & 3 deletions src/executable/6_data_ingress/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#include <library/work_contract.h>
#include <include/spsc_fixed_queue.h>
#include <include/jthread.h>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
bcpp::work_contract_group group;
std::jthread worker([&group](auto stopToken)
bcpp::detail::jthread worker([&group](auto stopToken)
{
while (not stopToken.stop_requested())
group.execute_next_contract();
Expand DownExpand Up@@ -47,4 +47,4 @@ int main()
worker.request_stop();
worker.join();
return 0;
}
}
6 changes: 5 additions & 1 deletion src/executable/benchmark/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,13 @@ PRIVATE
target_link_libraries(benchmark
PRIVATE
pthread
rt
work_contract
tbb_static
fmt
)

# rt library is only available on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(benchmark PRIVATE rt)
endif()

15 changes: 11 additions & 4 deletions src/executable/benchmark/main.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
#include <include/jthread.h>
#include <cstddef>
#include <iostream>
#include <memory>
Expand All@@ -7,7 +8,6 @@
#include <cstdint>
#include <atomic>
#include <vector>
#include <thread>
#include <cmath>
#include <iomanip>
#include <span>
Expand DownExpand Up@@ -42,7 +42,7 @@ std::size_t thread_local tlsCurrentTaskId;

std::atomic<bool> startTest = false;
std::atomic<bool> endTest = false;
std::vector<std::jthread> testThreads;
std::vector<bcpp::detail::jthread> testThreads;

#include "./test_harness.h"

Expand All@@ -53,10 +53,17 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
// Thread affinity can be set via thread_policy_set but it's more complex
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -125,7 +132,7 @@ auto create_worker_threads
auto index = 0;
for (auto & thread : testThreads)
{
thread = std::jthread([&readyThreadCount, work, threadId = index]
thread = bcpp::detail::jthread([&readyThreadCount, work, threadId = index]
(
) mutable
{
Expand DownExpand Up@@ -211,7 +218,7 @@ auto get_task_duration
bool volatile end = false;
bool volatile ready = false;
std::size_t total = 0;
std::jthread thread([&]()
bcpp::detail::jthread thread([&]()
{
ready = true;
while (!start)
Expand Down
11 changes: 9 additions & 2 deletions src/executable/signal_tree_benchmark/main.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
#include <ratio>
#include <functional>

#include <include/jthread.h>
#include <include/signal_tree.h>

// it might look a bit odd to hard code the cpus to use in the benchmark
Expand All@@ -38,10 +39,16 @@ bool set_cpu_affinity
int value
)
{
#ifdef __linux__
cpu_set_t cpuSet;
CPU_ZERO(&cpuSet);
CPU_SET(value, &cpuSet);
return (pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet) == 0);
#else
// macOS doesn't support CPU affinity via pthread_setaffinity_np
(void)value;
return true;
#endif
}


Expand DownExpand Up@@ -105,9 +112,9 @@ int main
activeThreadCount--;
};

std::vector<std::jthread> threads(num_threads);
std::vector<bcpp::detail::jthread> threads(num_threads);
for (auto & thread : threads)
thread = std::jthread(test);
thread = bcpp::detail::jthread(test);

while (activeThreadCount != num_threads)
;
Expand Down
Loading