标准实验闩锁和势垒使用ptrdiff_t [英] Standard experimental latch and barrier use ptrdiff_t

查看:80
本文介绍了标准实验闩锁和势垒使用ptrdiff_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 C ++并发性实验扩展,并注意到新的同步类 latch barrier flex_barrier .它们都实现了一次使用或可重复使用的标准屏障.

I was looking at the C++ experimental extensions for concurrency and noticed the new synchronization classes latch, barrier, and flex_barrier. They all implement a standard barrier, either single-use or reusable.

当前文档针对其构造函数声明了以下签名:

The current documentation states the following signature for their constructors:

explicit latch( ptrdiff_t value );
explicit barrier( std::ptrdiff_t num_threads );
explicit flex_barrier( std::ptrdiff_t num_threads );

具有 value num_threads 参数的以下说明:

With the following explanation for the value or num_threads parameter:

-内部计数器的初始值;一定是非负的

value - the initial value of the internal counter; must be non-negative

num_threads -的参与线程数障碍必须为非负数

num_threads - the number of participating threads for the barrier; must be non-negative

num_threads -flex_barrier的参与线程;必须为非负数

num_threads - the number of participating threads for the flex_barrier; must be non-negative


所有三个构造函数都接受 std :: ptrdiff_t ,这是一个有符号的整数类型.然后,文档明确指出该值必须为非负数.


All three constructors accept a parameter of type std::ptrdiff_t, which is a signed integer type. The documentation then explicitly states that the value must be non-negative.

我的问题:选择 std :: ptrdiff_t 类型作为参数类型而不是诸如

My question: what is the rationale for choosing the std::ptrdiff_t type as parameter type instead of an unsigned integer type such as std::size_t. It seems to me that using an unsigned integer type is safer as the constructor can then never be called with an invalid parameter value.

我知道当前定义是实验性的,并且倾向于更改,但是仍然可以将当前参数类型明确选择为带符号整数类型.因此,背后必须有某种思想,不是吗?

I know that the current definition is experimental and inclined to change, but still, the current parameter type was explicitly chosen to be a signed integer type. So there must be some kind of thought behind it, no?

推荐答案

此更改是在2015年2月在科隆举行的C ++ WG21会议上进行讨论之后做出的..AFAIK对具有无符号值的担心是负号可能会意外地转换为无符号值.就使用 short 而言,我们想确保这些概念在为GPU编写的应用程序中可用,这些应用程序中可能有大量的子任务.

This change was made after discussions at the C++ WG21 meeting in Cologne, in February 2015. I wasn't present, but I incorporated the WG's feedback into the document. AFAIK the concern about having an unsigned value was the a negative signed number might accidentally get cast to an unsigned value. As far as using short goes, we wanted to ensure that these concepts were usable in applications written for GPUs where there are potentially very large numbers of subtasks.

这篇关于标准实验闩锁和势垒使用ptrdiff_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆