随笔分类 -  并发

摘要:class ThreadRAII { public: // whether join or detach should be called, // when a this object is destroyed. enum class DtorAction { join, detach }; Thr 阅读全文
posted @ 2016-02-14 01:27 wu_overflow 阅读(292) 评论(0) 推荐(0)
摘要:std::mutex m; std::condition_variable cond; int flag = 0; constexpr int kLoopTimes = 10; void foo(int id){ for (int i = 0; i != kLoopTimes; ++i){ std: 阅读全文
posted @ 2015-11-19 19:40 wu_overflow 阅读(405) 评论(0) 推荐(0)
摘要:templateIterator parallelFind(Iterator first, Iterator last, MatchType match){ struct FindElement { void operator()(Iterator begin, Itera... 阅读全文
posted @ 2015-11-04 14:20 wu_overflow 阅读(169) 评论(0) 推荐(0)
摘要:class ThreadsJoiner{ std::vector& threads;public: ThreadsJoiner(std::vector& threads_): threads(threads_) {} ~ThreadsJoiner() ... 阅读全文
posted @ 2015-11-03 17:24 wu_overflow 阅读(389) 评论(0) 推荐(0)
摘要:templateT parallelAccumulate(Iterator first, Iterator last, T init){ size_t const length = std::distance(first, last); if (length == 0){ ... 阅读全文
posted @ 2015-10-24 18:44 wu_overflow 阅读(219) 评论(0) 推荐(0)
摘要:templatestruct AccumulateBlock{ T operator()(Iterator first, Iterator last) { return std::accumulate(first, last, T()); }};class Threa... 阅读全文
posted @ 2015-10-24 17:57 wu_overflow 阅读(157) 评论(0) 推荐(0)
摘要:templatestruct Sorter{ struct ChunkToSort { std::list data; std::promise> promise; }; ThreadSafeStack chun... 阅读全文
posted @ 2015-10-17 11:11 wu_overflow 阅读(240) 评论(0) 推荐(0)
摘要:templateclass ThreadSafeStack{private: std::stack data; mutable std::mutex m;public: ThreadSafeStack() = default; ThreadSafeStack(con... 阅读全文
posted @ 2015-10-16 14:24 wu_overflow 阅读(342) 评论(0) 推荐(0)
摘要:templateclass LockFreeStack{private: struct Node; struct CountedNode { int externalCount = 0; Node* ptr = nullp... 阅读全文
posted @ 2015-10-05 02:39 wu_overflow 阅读(224) 评论(0) 推荐(0)
摘要:constexpr size_t maxHazardPointers = 100;struct HazardPointer{ std::atomic id; std::atomic pointer;};array hazardPointers;class Hazard... 阅读全文
posted @ 2015-10-03 16:18 wu_overflow 阅读(715) 评论(1) 推荐(0)
摘要:templateclass LockFreeStack{private: struct Node { std::shared_ptr data; Node* next; Node(T const& value): ... 阅读全文
posted @ 2015-09-30 10:20 wu_overflow 阅读(342) 评论(0) 推荐(0)
摘要:templateclass ThreadsafeList{ struct Node { std::mutex m; std::shared_ptr data; std::unique_ptr next; Node(): ... 阅读全文
posted @ 2015-09-29 09:33 wu_overflow 阅读(1153) 评论(0) 推荐(0)
摘要:template>class ThreadsafeLookupTable{private: class BucketType { private: typedef std::pair bucketValue; typedef std::list buck... 阅读全文
posted @ 2015-09-27 10:06 wu_overflow 阅读(160) 评论(0) 推荐(0)
摘要:templateclass ThreadsafeQueue{private: struct Node { std::shared_ptr data; std::unique_ptr next; }; std::unique_... 阅读全文
posted @ 2015-09-26 09:18 wu_overflow 阅读(657) 评论(0) 推荐(0)
摘要:上一篇文章里说到了一个极简易队列的实现,然而它对于并发存在一个问题,就是当多个或者说就是两个线程并发地访问队列,分别调用 push() 与 tryPop() 时,可能就会导致数据争用或者死锁。以下是一种思路,通过分离数据允许并发。其大致思路是预先分配一个不储存任何数据的结点占位,当 push() 进... 阅读全文
posted @ 2015-09-24 18:48 wu_overflow 阅读(310) 评论(0) 推荐(0)
摘要:templateclass ThreadsafeQueue{private: mutable std::mutex _mut; std::queue> _dataQueue; std::condition_variable _dataCo... 阅读全文
posted @ 2015-09-23 01:21 wu_overflow 阅读(277) 评论(0) 推荐(0)