加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如果ANSI C不支持多线程,那么非托管C应用程序如何成为多线程?

发布时间:2020-12-16 10:51:52 所属栏目:百科 来源:网络整理
导读:我听说C不提供多线程的原生支持.我假设多线程C应用程序依赖托管代码进行多线程处理;也就是说,例如,Visual C应用程序使用MFC或.NET或类似的东西来提供多线程功能.我进一步假设某些或所有托管代码功能对于非托管应用程序不可用.但我读过有关非托管多线程应用程
我听说C不提供多线程的原生支持.我假设多线程C应用程序依赖托管代码进行多线程处理;也就是说,例如,Visual C应用程序使用MFC或.NET或类似的东西来提供多线程功能.我进一步假设某些或所有托管代码功能对于非托管应用程序不可用.但我读过有关非托管多线程应用程序的内容.这怎么可能?我的哪些假设是假的?

解决方法

操作系统完全取决于为多线程提供支持.在 Windows上,可通过Win32 API获得必要的功能.诸如 MFC之类的框架为低级线程函数提供了包装以简化操作,当然.NET / CLR有自己的托管接口来访问Win32多线程功能.

在this article(C中的多线程)中提供了一个很好的解释.

Why Doesn’t C++ Contain Built-In
Support for Multithreading?

C++ does not contain any built-in
support for multithreaded
applications. Instead,it relies
entirely upon the operating system to
provide this feature. Given that both
Java and C# provide built-in support
for multithreading,it is natural to
ask why this isn’t also the case for
C++. The answers are efficiency,
control,and the range of applications
to which C++ is applied. Let’s examine
each.

By not building in support for multithreading,C++ does not attempt to define a “one size fits all” solution. Instead,C++ allows you to directly utilize the multithreading features provided by the operating system. This approach means that your programs can be multithreaded in the most efficient means supported by the execution environment. Because many multitasking environments offer rich support for multithreading,being able to access that support is crucial to the creation of high-performance,multithreaded programs.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读