简体   繁体   English

Win32 多线程编程

[英]Win32 Multithreaded Programming

A totally noob question.一个完全菜鸟的问题。 Inside Windows.窗户内。 Is it possible to make a thread without directly or indirectly calling a Win32 API function?是否可以在不直接或间接调用 Win32 API 函数的情况下创建线程? For example using assembly language to call opcodes that make the CPU do atomic operations.例如使用汇编语言调用使 CPU 执行原子操作的操作码。 I'm not certain but I'm guessing that the purpose of the OS is to provide this sort of thing.我不确定,但我猜操作系统的目的是提供这种东西。 Though I'm not sure.虽然我不确定。

Are these sort's of threading things like CreateThread() and fork() provided by the OS fundamental for everything to be built on top or was it provided as a convenience?操作系统基础提供了诸如 CreateThread() 和 fork() 之类的线程处理功能,以便在其上构建所有内容,还是为了方便而提供?

When It comes to making processes and threads can you roll your own or must you use what the OS provides?在制作进程和线程时,您可以自己推出还是必须使用操作系统提供的内容?

Atomics are a feature provided by the CPU.原子是 CPU 提供的一项功能。 In general, if there's a CPU operation that you can perform, you can perform it, excepting those instructions reserved for a lower "ring" level.一般来说,如果有可以执行的 CPU 操作,则可以执行它,但保留给较低“环”级别的那些指令除外。

Threads are a feature provided by the operating system.线程是操作系统提供的一项功能。

As such you can't create threads 1 using assembly code, your user-space code does not have the requisite permissions.因此,您无法使用汇编代码创建线程1 ,您的用户空间代码没有必要的权限。 You must make the proper operating system kernel calls to request a new thread.您必须进行适当的操作系统内核调用以请求新线程。

Threads don't really exist except as a function of what the operating system kernel does.除了作为操作系统内核的功能之外,线程并不真正存在。 One of the primary functions of a kernel is to manage threads and to schedule them on to the available compute resources.内核的主要功能之一是管理线程并将它们调度到可用的计算资源上。


1 This ignores things like virtualization or hypervisor features where your code can , but at a different level than the parent OS. 1这会忽略您的代码可以使用的虚拟化或虚拟机管理程序功能,但与父操作系统的级别不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM