c++11 thread

关于 c++11 的线程库,我们有如下几个问题: 可否不传参数 可否传递多个参数 可否传递 const 参数 可否传递引用参数 可否传递 const 引用参数 std::thread 结构可否放入容器 std::thread 可否在类内部使用 针对以上问题,我们先来看一个标准的 c++11 线程库要怎么使用: #include <stdio.h> #include <thr……

阅读全文

36 进制

看到同事桌上有一份面试题,有一个 36 进制运算的题目,手贱敲了一下,不调真的不好做啊 #include <stdio.h> #include <string> #include <algorithm> #include <math.h> int convert_36_10(std::string strNum) { std::reverse(strNum.begin(), strNum.end()); int n = 0; for (……

阅读全文

netty 初窥

先说结论,总体感觉很好,比 cpp 上的 nio 框架好。 缘起是一个同学来问 java web 的问题,帮他调了一下,两年没怎么碰过 java web 的东西了,各种生疏,而且在调试的过程中,也再次感觉到 java 这个东西实在不适合做 web,一个是重,ssh 框架一上来就给人压得喘不过气的感觉,新增一个功能,要 spring struts 里面 xml ……

阅读全文

boost optional 以及 operator bool

boost 库有一个组件,叫做 optional,用来保存一些可有可无的成员变量,说明见这里,http://www.boost.org/doc/libs/…,样例用法如下 #include <boost/optional.hpp> #include <stdio.h> #include <string> int main() { boost::optional<std::string> name; if (name) ……

阅读全文

动态链接库中的全局变量

想给自己之前的日志库,加一个染色的功能 gcc 有一个自己的特性,叫 __thread,介绍可以看这里,https://gcc.gnu.org/onlinedocs…,是可以用来修饰一个全局变量,从而让这个全局变量在每个线程都有一份拷贝,例子如下: #include <stdio.h> #include <unistd.h> #include <pthread.h> #inc……

阅读全文

(void)var 是在干嘛

最近在看 muduo 的代码,看到类似这样的写法: size_t n = activeTimers_.erase(timer); assert(n == 1); (void)n; 而且不止一处,于是就很好奇,这种 (void)var 是在干嘛,查了一下,这里说道,http://stackoverflow.com/quest… It works around some compiler warnings. Some compilers will warn if you ……

阅读全文