mutex
cpp condition_variable wait_until unique_mutex time_out
#include <chrono> #include <condition_variable> #include <ctime> #include <fstream> #include <future> #include <iomanip> #include <iostream> #include ......
go语言sync.Mutex
go语言sync.mutex 数据结构 type Mutex struct { state int32 sema uint32 } Mutex包含了两个字段,分别是state、sema,state表示了当前锁的状态,sema是用于控制锁的一个信号量。这是一个零值可用的结构体,零值表示未加锁 stat ......
golang pprof 监控系列(3) —— memory,block,mutex 统计原理
golang pprof 监控系列(3) —— memory,block,mutex 统计原理 大家好,我是蓝胖子。 在上一篇文章 golang pprof监控系列(2) —— memory,block,mutex 使用里我讲解了这3种性能指标如何在程序中暴露以及各自监控的范围。也有提到memory ......
c++ 多线程编程std::thread, std::shared_mutex, std::unique_lock
在C++11新标准中,可以简单通过使用thread库,来管理多线程,使用时需要#include <thread>头文件。 简单用例如下: 1 std::thread(Simple_func); 2 std::thread t(Simple_func); 3 t.detach(); 第一行是直接启动一 ......
使用C++代码实例说明pthread_mutex_t是不可重入的,并提出解决方法
函数不可重入:函数运行被打断以后,不能恢复运行或运行结果不符合预期。 Linux下的pthread_mutex_t控制的代码区域默认是不可重入的。下面是一个使用C++代码演示pthread_mutex_t不可重入的例子: #include <iostream> #include <pthread.h ......
golang mutex底层原理
数据结构 位于sync/mutex.go type Mutex struct { state int32 sema uint32 } state locked:锁的状态,是否已经上锁 woken:表示是否有协程被唤醒,0表示没有协程被唤醒,1表示有协程被唤醒 starving:是否处于饥饿模式 wa ......
golang pprof监控系列(2) —— memory,block,mutex 使用
golang pprof监控系列(2) —— memory,block,mutex 使用 大家好,我是蓝胖子。 profile的中文被翻译轮廓,对于计算机程序而言,抛开业务逻辑不谈,它的轮廓是是啥呢?不就是cpu,内存,各种阻塞开销,线程,协程概况 这些运行指标或环境。golang语言自带了工具库来 ......
cpp once_flag,call_once in mutex
//util.h #pragma once #include <chrono> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <memory> #i ......