日积月累

1. C++ typedef typename用法

https://blog.csdn.net/zhangxiao93/article/details/50569924
简单说:
typedef typename std::vector<T>::size_type size_type;
表示: typedef创建了存在类型的别名,而typename告诉编译器std::vector::size_type是一个类型而不是一个成员。

2.没搞懂为什么会是这样的。。智能指针。。第一个为什么会死锁

// void setStuff(const sp<Stuff>& stuff) {
//   std::lock_guard<std::mutex> lock(mMutex);
//   mStuff = stuff;
// }

// is very dangerous. This code WILL deadlock one day or another.

// What isn't obvious is that ~Stuff() can be called as a result of the
// assignment. And it gets called with the lock held. First of all, the lock is
// protecting mStuff, not ~Stuff(). Secondly, if ~Stuff() uses its own internal
// mutex, now you have mutex ordering issues.  Even worse, if ~Stuff() is
// virtual, now you're calling into "user" code (potentially), by that, I mean,
// code you didn't even write.

// A correct way to write this code is something like:

// void setStuff(const sp<Stuff>& stuff) {
//   std::unique_lock<std::mutex> lock(mMutex);
//   sp<Stuff> hold = mStuff;
//   mStuff = stuff;
//   lock.unlock();
// }

3. 智能指针

https://www.jianshu.com/p/dff8530dffd7 例子不错。

4. android多媒体开发:

http://windrunnerlihuan.com/2016/11/28/Android多媒体开发-一-MediaPlayer框架开始/

http://windrunnerlihuan.com/2016/11/30/Android多媒体开发-二-MediaPlayer的C-S架构以及C-层调用步骤/

http://windrunnerlihuan.com/2016/06/12/Binder简要分析/

http://www.cnblogs.com/xkfz007/archive/2012/08/12/2613690.html

http://blog.csdn.net/shingle_/article/details/51924859

视频+三本经典书籍+一本中文书籍
https://github.com/chocoluffy/Machine-Learning-Course/blob/master/Bishop - Pattern Recognition and Machine Learning.pdf

5. C++并发编程实战:

  1. 只执行一次的: std::once_flag 和 std::call_once 配合使用
  2. std::future和std::shared_future和std::async 配合的异步测试
  3. std::packaged_task
  4. std::promise
  5. CSP的思想:如果没有共享数据,则每个线程可以完全独立地推理得到,只需基于它对所接收到的消息如何进行反应。这种编程的方式其实就是做了一个状态机,在不同的状态做不同的事情避免过多的数据竞争。
  6. 角色模型:将事情按角色进行分配,不同的线程负责不同的部分,避免数据竞争。p95的ATM的例子。

多线程代码设计的一些原则:

  1. 线程任务的划分(处理前分好;递归划分;按任务类型分)

  2. 影响并发代码性能的因素(CPU个数的影响,实际可以并行的线程数,过度订阅和过多任务切换的问题;多CPU之前多缓存之期间的乒乓缓存的问题;)

  3. 线程池(工作窃取(有的线程任务过多,其他线程没事做);在工作线程上的数据竞争;中断线程)

  4. void wait( std::unique_lockstd::mutex& lock );
    template< class Predicate >
    void wait( std::unique_lockstd::mutex& lock, Predicate pred );
    wait的实现原理,在收到notify_one/notify_all()的时候,
    a.加锁,
    b. 再检查这个pred是不是为true,为true,wait返回,并继续向下执行;为false,block线程,解锁,继续等下去。

unique_ptr : 不能进行赋值操作,只能使用std::move进行“赋值”(所有权的转移),转移后,之前的指针就被析构了。
share_ptr :相当于Android中的强指针
weak_ptr:相当于Android中的弱指针,这两个是为了解决相互引用中无法释放的问题
如果有相互引用,则一个写强指针一个写弱指针。

6 同步异步IO 阻塞和非阻塞

https://www.cnblogs.com/euphie/p/6376508.html
https://blog.csdn.net/davidsguo008/article/details/73556811

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值