并行快速排序

本文详细探讨了并行快速排序的原理和实现,通过利用多核处理器的并行性提高排序效率。我们深入分析了如何将传统快速排序的递归过程转化为并行任务,并介绍了使用C++实现的并行快速排序算法,包括任务分解、线程同步和性能优化等方面的关键点。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <list>
#include <future>
#include <thread>
#include <iostream>
#include <stack>
#include <thread>
#include <mutex>
#include <exception>


struct empty_stack :std::exception
{
	const char* what() const throw();

};

template<typename T>
class thread_safe_stack
{
public:

	thread_safe_stack() {}


	thread_safe_stack(const thread_safe_stack& other)
	{
		std::lock_guard<std::mutex> lock(other.mtx);
		stack = other.stack;
	}
	void push(T value)
	{
		std::lock_guard<std::mutex> lock(mtx);
		stack.push(std::move(value));
	}

	std::shared_ptr<T> pop()
	{
		std::lock_guard<std::mutex> lock(mtx);
		if (stack.empty())
			throw empty_stack();
		std::shared_ptr<T> const res(std::make_shared<T>(std::move(stack.top())));
		stack.pop();
		return res;
	}

	bool empty()const
	{
		std::lock_guard<std::mutex> lock(mtx);
		return stack.em
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yshuise

权术横行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值