为什么OCaml的线程被认为是“不够”? [英] Why OCaml's threading is considered as `not enough`?

查看:142
本文介绍了为什么OCaml的线程被认为是“不够”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来很多人都说OCaml并没有很好的并发能力,它也不适合Web服务器应用程序。



我目前正在学习 ocaml的手册。看来OCaml现在提供了并发。



我能知道为什么OCaml的并发/线程被认为是不好的吗?



我可以在OCaml中开发服务器应用程序吗?我可能遇到什么问题? 解决方案

请参阅并发与并行 - 有什么区别?。 OCaml的线程提供并发性,因为您可以在上一个函数完成之前启动下一个函数。但OCaml不提供并行性,所以当第二个函数启动时,第一个函数必须暂停。两个线程不能同时运行,因此一个进程中的多个CPU限制计算会相互阻塞,并且不能在一个进程中最大化所有CPU内核。



OCaml的线程就是人们的牛肉。这是否意味着你不能使用OCaml作为服务器之类的东西?不是的。这是你在服务器设计中必须考虑的事情,但它通常不是一个炫耀者。哎呀,Node.js是直接单线程的,但它的主要目的是创建服务器。


It seems many people are saying OCaml does not have a good capacity for concurrency and it is also not good for web server applications.

I am currently learning ocaml's manual. It seems that OCaml provide concurrency now.

Can I know why OCaml's concurrency/threading is considered as bad?

Can I develop server application in OCaml? What problems may I meet?

解决方案

See Concurrency vs. parallelism — What's the difference?. OCaml's threads offer concurrency, as you can have the next function start before the previous one is finished. But OCaml does not offer parallelism, so when that second function starts, the first one has to be put on hold. Two threads cannot run simultaneously, so multiple CPU-bound computations in a process will block each other, and you can't max out all your CPU cores in one process.

That's people's beef with OCaml's threading. Does it mean you can't use OCaml for something like a server? No. It's something you will have to take into account in your server design, but it's not generally a showstopper. Heck, Node.js is straight-up single-threaded, yet its main purpose is creating servers.

这篇关于为什么OCaml的线程被认为是“不够”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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