您的位置:首页 > 教育 > 锐评 > 遵义seo快速排名_网页制作模板蛋糕_产品营销策划_深圳seo优化

遵义seo快速排名_网页制作模板蛋糕_产品营销策划_深圳seo优化

2025/4/20 23:13:53 来源:https://blog.csdn.net/Word_And_Me_/article/details/144201562  浏览:    关键词:遵义seo快速排名_网页制作模板蛋糕_产品营销策划_深圳seo优化
遵义seo快速排名_网页制作模板蛋糕_产品营销策划_深圳seo优化

1、c++

#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>
#include <thread>
#include <atomic>using namespace std;const int NUM_THREADS = 1; // 线程数量std::atomic<int> frameCounts[NUM_THREADS];  // 每个线程的帧计数
std::atomic<bool> running(true);            // 控制定时器的运行状态
std::mutex printMutex;// 定时器函数,记录每个线程的FPS
void timer(int threadIndex) {while (running) {// 等待1秒std::this_thread::sleep_for(std::chrono::seconds(1));// 打印并重置当前线程的帧数int fps = frameCounts[threadIndex].exchange(0);{std::lock_guard<std::mutex> lock(printMutex);std::cout << "Thread " << threadIndex << " FPS: " << fps << std::endl;}}
}int main() {std::thread t(timer, 0);t.detach();while (true) {frameCounts[0]++;}system("pause");return 0;
}

输出:

2、Python

from multiprocessing import Process, Lock, Value
import timeclass Timer(Process):def __init__(self, lock, crt_time, last_time):super().__init__()self.current_time = current_timeself.last_time = last_timeself.lock = lockdef run(self):while True:# 等待1stime.sleep(1)with self.lock:self.last_time.value = self.current_time.valueprint('----------num----------:', self.last_time.value)self.current_time.value = 0if __name__ == '__main__':lock = Lock()# 使用 Value 创建共享变量current_time = Value('i', 0)  # 'i' 表示整数类型last_time = Value('i', 0)timer = Timer(lock, current_time, last_time)timer.start()while True:with lock:timer.current_time.value += 1

输出:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com