mirror of
https://github.com/baz-scm/awesome-reviewers.git
synced 2025-08-20 18:58:52 +03:00
1.7 KiB
1.7 KiB
title, description, repository, label, language, comments_count, repository_stars
| title | description | repository | label | language | comments_count | repository_stars |
|---|---|---|---|---|---|---|
| Framework synchronization practices | When implementing concurrent code, always use the framework's provided synchronization primitives rather than direct language features. This ensures compatibility across all build configurations and platforms: | opencv/opencv | Concurrency | C++ | 4 | 82865 |
When implementing concurrent code, always use the framework's provided synchronization primitives rather than direct language features. This ensures compatibility across all build configurations and platforms:
- Use OpenCV synchronization mechanisms like
cv::getInitializationMutex()andcv::AutoLockinstead of standard C++ constructs likestd::mutexandstd::lock_guard:
// Instead of this:
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
// Use this:
cv::AutoLock lock(cv::getInitializationMutex());
- Respect system threading settings with
cv::getNumThreads()rather than hardcoding thread counts:
// Instead of this:
m_parallel_runner = JxlThreadParallelRunnerMake(nullptr, 8); // Hardcoded value
// Use this:
m_parallel_runner = JxlThreadParallelRunnerMake(nullptr, cv::getNumThreads());
-
Be aware that thread counts vary by platform (e.g., Android defaults to 2, Linux uses all cores) and that nested parallel operations may be serialized.
-
When using static resources in multithreaded contexts, ensure proper synchronization or consider alternatives like on-demand initialization that avoid static state altogether.
These practices ensure your code remains compatible with special configurations like OPENCV_DISABLE_THREAD_SUPPORT while maintaining optimal performance across various platforms.