什么是“火花"?在哈斯克尔 [英] What is a "spark" in Haskell

查看:24
本文介绍了什么是“火花"?在哈斯克尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对火花"的概念感到困惑

I'm confused about the notion of "spark"

它是 Haskell 中的一个线程吗?或者是产生新线程的动作?

Is it a thread in Haskell? Or is the action of spawning a new thread ?

谢谢大家:

总而言之,sparks 不是线程,而是更多的计算单元(用 C#/Java 术语来说是任务).所以这是实现任务并行的 Haskell 方式.

So to summarize, sparks are not thread but more of unit of computation (tasks to put it in C#/Java terms). So it's the Haskell way of implementing the task parallelism.

推荐答案

Sparks 不是线程.forkIO 引入了 Haskell 线程(映射到较少的真实操作系统线程上).Sparks 为每个线程在工作队列中创建条目,如果线程空闲,它们将从这些条目中执行任务.

Sparks are not threads. forkIO introduces Haskell threads (which map down onto fewer real OS threads). Sparks create entries in the work queues for each thread, from which they'll take tasks to execute if the thread becomes idle.

因此,spark 非常便宜(您可能在一个程序中拥有数十亿个,而您可能不会拥有超过一百万个 Haskell 线程,并且在六个内核上只有不到 12 个 OS 线程).

As a result sparks are very cheap (you might have billions of them in a program, while you probably won't have more than a million Haskell threads, and less than a dozen OS threads on half a dozen cores).

这样想:

这篇关于什么是“火花"?在哈斯克尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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