当前位置: 首页 > news >正文

如何重新做公司网站wordpress 悬停遮罩

如何重新做公司网站,wordpress 悬停遮罩,客户做网站嫌贵了,乐清柳市网一、线程池设计 概念#xff1a;线程池是一种管理线程资源的机制#xff0c;预先创建一定数量的线程#xff0c;当有任务提交时#xff0c;从线程池中获取线程执行任务#xff0c;任务完成后线程不会销毁而是返回线程池等待下一个任务。核心组件 线程管理器#xff1a;负…一、线程池设计 概念线程池是一种管理线程资源的机制预先创建一定数量的线程当有任务提交时从线程池中获取线程执行任务任务完成后线程不会销毁而是返回线程池等待下一个任务。核心组件 线程管理器负责创建、销毁和管理线程。任务队列存储待执行的任务。任务接口定义任务的执行方式。 C实现示例 #include vector #include queue #include memory #include thread #include mutex #include condition_variable #include future #include functional #include stdexceptclass ThreadPool { public:ThreadPool(size_t threads);templateclass F, class... Argsauto enqueue(F f, Args... args) - std::futuretypename std::result_ofF(Args...)::type;~ThreadPool(); private:// 工作线程集合std::vectorstd::thread workers;// 任务队列std::queuestd::functionvoid() tasks;// 同步相关std::mutex queue_mutex;std::condition_variable condition;bool stop; };// 构造函数创建指定数量的工作线程 inline ThreadPool::ThreadPool(size_t threads): stop(false) {for(size_t i 0; i threads; i) {workers.emplace_back([this] {while(true) {std::functionvoid() task;{std::unique_lockstd::mutex lock(this-queue_mutex);this-condition.wait(lock, [this] { return this-stop || !this-tasks.empty(); });if(this-stop this-tasks.empty())return;task std::move(this-tasks.front());this-tasks.pop();}task();}});} }// 添加新的任务到线程池 templateclass F, class... Args auto ThreadPool::enqueue(F f, Args... args) - std::futuretypename std::result_ofF(Args...)::type {using return_type typename std::result_ofF(Args...)::type;auto task std::make_sharedstd::packaged_taskreturn_type()(std::bind(std::forwardF(f), std::forwardArgs(args)...));std::futurereturn_type res task-get_future();{std::unique_lockstd::mutex lock(queue_mutex);// 不允许向已停止的线程池添加任务if(stop)throw std::runtime_error(enqueue on stopped ThreadPool);tasks.emplace([task]() { (*task)(); });}condition.notify_one();return res; }// 析构函数销毁线程池 inline ThreadPool::~ThreadPool() {{std::unique_lockstd::mutex lock(queue_mutex);stop true;}condition.notify_all();for(std::thread worker : workers) {worker.join();} }使用示例 // 创建一个包含4个线程的线程池 ThreadPool pool(4);// 向线程池提交任务 std::vectorstd::futureint results;for(int i 0; i 8; i) {results.emplace_back(pool.enqueue([i] {std::cout hello i std::endl;std::this_thread::sleep_for(std::chrono::seconds(1));std::cout world i std::endl;return i*i;})); }// 等待所有任务完成并获取结果 for(auto result : results)std::cout result.get() ; std::cout std::endl;二、锁优化 读写锁 概念读写锁允许多个线程同时读取共享资源但在写操作时会独占资源实现“多读单写”的机制。C实现 #include shared_mutex // C17引入 #include mutex #include map #include stringclass ThreadSafeHashMap { private:mutable std::shared_mutex mtx;std::mapstd::string, int data;public:// 读操作允许多个线程同时进行int get(const std::string key) const {std::shared_lockstd::shared_mutex lock(mtx);auto it data.find(key);return it ! data.end() ? it-second : -1;}// 写操作独占锁void set(const std::string key, int value) {std::unique_lockstd::shared_mutex lock(mtx);data[key] value;} };适用场景适用于读多写少的场景如缓存系统。 无锁队列 概念无锁队列使用原子操作替代传统的锁机制避免线程阻塞提高并发性能。C实现基于CAS操作 #include atomic #include memorytemplatetypename T class LockFreeQueue { private:struct Node {T data;std::atomicNode* next;Node(const T value) : data(value), next(nullptr) {}};std::atomicNode* head;std::atomicNode* tail;public:LockFreeQueue() : head(nullptr), tail(nullptr) {}void enqueue(const T value) {Node* newNode new Node(value);Node* oldTail tail.load();while (!tail.compare_exchange_weak(oldTail, newNode)) {}if (oldTail) {oldTail-next newNode;} else {head newNode;}}bool dequeue(T value) {Node* oldHead head.load();while (oldHead) {Node* next oldHead-next.load();if (head.compare_exchange_weak(oldHead, next)) {value oldHead-data;delete oldHead;return true;}}return false;}~LockFreeQueue() {T value;while (dequeue(value)) {}} };适用场景适用于高性能要求的生产者-消费者模型。 性能对比与选择策略 技术优点缺点适用场景传统互斥锁实现简单适用广泛线程阻塞上下文切换开销大竞争不激烈的场景读写锁提高读并发性能实现复杂写操作可能饥饿读多写少的场景无锁队列无阻塞高性能实现复杂调试困难高性能要求的队列操作 在实际应用中需要根据具体场景选择合适的并发技术必要时可以组合使用多种技术以达到最佳性能。
http://www.dnsts.com.cn/news/199927.html

相关文章:

  • quiz在哪个网站做阿里云支持wordpress
  • 信游天下网站建设成都可以做网站的公司
  • 对接 网站后台海南省人才在线
  • 建站平台与建站系统网站开发属于什么类型软件
  • 团购网站建设惠州企业网站设计
  • 深圳做网站建设的公司鄂北局网站建设者风采
  • 微网站建设 合同网页设计作品展示 简单
  • 网站开发流程人物网站建设开发价格怎么算
  • 在哪里查企业信息最准确完备的常州网站优化
  • 不花钱自己可以做网站吗软件工程专业考研学校排名
  • 廊坊网站排名优化公司百度投放广告一天多少钱
  • 做抢单软件的网站制作手机网站工具
  • 竞价网站单页谷歌搜索入口
  • net网站开发网站视频接口 怎么做
  • 网站怎么发布到服务器wordpress 自动评论软件
  • 怎么做网站数据库无锡百度快照优化排名
  • 淘客网站怎么与pid做网站网站犯法吗
  • 网站的内部优化网站开发常用jquery插件
  • 学网站开发多久个人小程序怎么做
  • 资料大全正版资料徐州seo公司
  • 中国建设银行济南招聘信息网站中山建设厅网站
  • 帮别人做网站要投资吗ulysses wordpress
  • 网站开发国内外研究背景网站二次开发是什么意思
  • 网站的建站过程杭州百家号优化
  • 临淄网站建设yx718网站留言板作用
  • t恤定制网站哪个好网站开发代码归属
  • html5网站开发环境的搭建网站设计费报价表
  • 腾讯与中国联通长沙百度快照优化排名
  • 上海保洁服务网站建设做网站接专线费用
  • 杭州模板网站建设wordpress页面排版