- 博客(25)
- 收藏
- 关注
翻译 C++ Future and Promise
C++ future and promise and async():本文详细介绍C++的future, promise以及async()功能。使用这几个功能需要在source code里面加上#include<future>一个简单的例子:新建一个线程,计算N的阶乘,并存储到x中。一个简单的实现是这个样子的:void factorial(int N, int& x){ int res = 1; for(int i = N; i > 1; i--){ res
2020-11-30 05:10:34
380
原创 C++ Multithreading(4) -- event handling
Event handlingEvent handling in C++ multithreading:global variablecondition variableEvent handling in C++ multithreading:当有多个线程同时存在的时候,可能一个线程需要等另一个线程完成某个任务,或者等某一个条件被设置为真才可以继续运行。比如:线程1负责处理数据线程2负责读取数据那么线程1一定要等到线程2读取到了所需数据之后,才可以继续执行。假如我们有一个应用,这个应用有三个ta
2020-06-12 10:11:09
312
原创 C++ Multithreading(3) -- passing arguments to threads
线程传参passing arguments to threadscaveat:pass stack-located local variable to threadspass heap-located variable to threadshow to pass by reference:pass pointer to member function of a class as thread functionpassing arguments to threads给thread传参很简单,直接将call
2020-06-12 01:19:45
313
原创 C++ Multithreading (2) -- joining/detaching threads
本文介绍如下几点create and join threadscreatejoincreate a thread using function pointercreate a thread using function objectcreate a thread using Lambda functionget thread IDdetach threadspass arguments to th...
2020-06-05 11:14:00
207
原创 C++ alias template
C++ alias templatetype aliastypedefusingtypedef和using的区别alias template:type aliastype alias就是将某一个type重新命名为另一个更加直观简单的名字。C++中有两种type alias:typedeftypedef [original-type] [your-alias];比如:typedef int Pixel;Pixel p = 1; // 等价于 int p = 1;typedef std::m
2020-06-05 10:02:10
744
原创 C++ Multithreading (1) -- creating threads
Three ways to create threadsintroductionthread creationcreating threads with function pointercreating threads with function objectscreating threads with lambda functionintroduction一开始,C++是不支持多线程的,直到C++ 11开始,才真正引入了多线程这个概念和标准库。如果想在cpp文件,比如project.cpp里面使用多
2020-06-05 09:25:00
307
原创 GDB Tutorial
GDB tutorialGDB overviewload executable file into GDBrun program in GDBquit GDBGDB commandsbreaknextlistprintup / downdisplay / undisplaybacktracestepcontinuefinishwatchinfo breakpoints (i b)delete (d...
2020-05-04 02:44:51
355
翻译 C++ getopt
本文讲解如何处理命令行传入的选项和参数getopt()getopt_long()getopt_long_only()example比如我们执行如下指令会输出file文件的前10行:head file // 默认输出file的前10行如果我们想要输出文件的前50行,就可以加选项"-n"和参数50head -n 50 file通过传入-n 50, head程序就知道我们想要得到是前50行...
2020-04-25 08:58:36
1277
原创 C++ Lambda function
Lambda FuctionDefinitionNeed of Lambda functionsHow to pass outer scope elements inside Lambda functionsDefinitionlambda function也可以称之为匿名function,你可以向lambda function传入参数,lambda function也可以返回参数,它和fun...
2020-04-23 08:51:05
2081
原创 C++ Function object
本文介绍C++ standard library中的function objectdefinitioncreate a function objectfunction object VS function优势1:优势2:definition只要一个class/struct实现了operator(),就可以称之为function object(或者functor)。create a funct...
2020-04-23 08:17:32
661
原创 C++ Smart pointer
Smart pointer in C++什么是smart pointer为什么要使用smart pointer常用的smart pointer以及使用方法shared pointersunique pointerssmart pointer背后的故事什么是smart pointer一般在C/C++中,如果我们使用了pointer来指向某块heap区域,当不再需要这块区域的时候,我们需要手动删除...
2020-04-16 03:40:04
463
翻译 C++ Condition variable
如果你的线程需要改变某个变量,改动完成之后通知另一个线程持续等待,直到收到某一个线程发来的通知那么就可以放心食用std::condition_variable了。下面用一个例子来介绍什么是condition variable以及怎么使用:妈妈和儿子的故事:儿子在外面玩,衣服脏了。儿子说:“妈妈帮我洗衣服”。妈妈说:“好的吧”。那么总结起来,可以用两个functions来表示这...
2020-04-13 23:36:22
404
原创 C++ Locks
C++ Locksstd::mutexdeadlockstd::lock_guardTo avoid deadlockstd::unique_lockTo avoid deadlockTo get higher parallelizationConditional variable requires std::unique_lockstd::mutexmutex是C++中的一个可以加锁的obj...
2020-04-13 12:01:21
359
原创 C++ keywork explicit
最近code的时候遇到一个warning,虽然不是error,但是也值得好好说一下:Warning: Single-argument constructors must be marked explicit to avoid unintentional implicit conversions在之前的文章中谈到了implicit conversion和operator conversion...
2020-04-12 07:22:04
394
原创 C++ conversion operator
本文主要会介绍:implicit conversionconversion operatorimplicit conversion有时候我们传入的参数并不是function想要的类型,但是依然可以运行,这是因为C++ compiler在底层悄悄帮我们进行了type conversion,比如:class entity{private: int a;public: en...
2020-04-12 05:48:11
1219
1
原创 C++ object initialization
在C++中,即使是非常简单的初始化也有很多需要了解的东西,总结起来,一共分为以下几个部分:initializer listuniform initializationcopy initializationInitializer list在C++ 11之前,可以用一组数值来初始化一个C类型的数组,但是如果想要初始化一个vector, map或者任何其他类型的container, 只...
2020-04-12 03:35:11
415
原创 A deep dive into /proc/cpuinfo
A deep dive into /proc/cpuinfoBackground knowledge/proc/cpuinfo is a read only file, which shows each logic CPU with a unique processor number. A logical CPU can be a hyperthreading sibling, a share...
2020-03-14 06:35:33
516
转载 A Simple Makefile Tutorial
A Simple Makefile TutorialWhat is MakefileWhy we need MakefileHow to create a MakefileWhat is MakefileMakefile is a simple way to organize code compilation. Why we need MakefileAssuming that we ...
2019-11-27 06:01:44
150
原创 windows下开发jvmti agent详细教程
目录目录JAVA虚拟机(JVM:Java Virtual Machine)简介JVMTI以及agent简介1.JVMTI(Java Virtual Machine Tool Interface)2.agent平台环境以及软件安装实现第一步:创建java源文件第二步:实现C/C++动态链接库第三步:调用动态链接库JAVA虚拟机(JVM:Ja...
2018-03-26 11:39:32
1920
原创 JPS没有输出结果的原因和解决方法
最近在部署Hadoop集群,启动集群之后,使用jps查看启动状态。master服务器的输出如下:其中一台119服务器输出如下:但是服务器118使用jps之后却没有任何输出。经过检查,118上面的datanode是启动成功并且能够正确运行的。后来发现,jps没有输出不是集群配置出错,而是权限出问题。java程序启动以后,会在/tmp目录下生成一个hsperfdata_username的文件夹,这
2017-08-12 16:29:23
11653
2
原创 【图解】Dev C++单步调试的方法
Step 1 : 在选项【调试】中选择【切换断点】 Step 2 : 选择【切换断点】之后,第一行会自动被选中; 然后手动在选择一个断点,经过反复测试,一般选择int main() 之后的一行会比较好调试(如图所示)。 Step 3 : 选择【运行到光标】Step 4 :
2016-07-18 20:42:15
8031
原创 贪婪算法求解TSP问题:
贪婪算法求解TSP问题:贪婪算法(greedy algorithm) 贪心法,又称贪心算法、贪婪算法、或称贪婪法,是一种在每一步选择中都采取在当前状态下最好或最优(即最有利)的选择,从而希望导致结果是最好或最优的算法。 贪心算法在有最优子结构的问题中尤为有效。最优子结构的意思是局部最优解能决定全局最优解。简单地说,问题能够分解成子问题来解决,子问题的最优解能递推到最终问题的最优解。 T
2016-07-18 20:34:58
5491
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人