我用代码块编写了一个程序,代码如下所示。
notificationCellRendererFunc(params) {
var self = this;
var eSpan = document.createElement('button');
console.log(params.value); // logs notificationId
eSpan.innerHTML = 'Resend';
eSpan.id = params.value;
eSpan.addEventListener('click', function (eSpan) {
alert(eSpan.toElement.id);
var notificationFilter: any = {};
notificationFilter.notificationId = eSpan.toElement.id;
self.notificationService.ResendNotification(notificationFilter)
.subscribe(
(data: any) => {
console.log('in save')
},
err => { console.log(err) }, // error
);
});
return eSpan;
}
在程序中,我没有使用任何多线程函数和库,例如windows.h或thread.h。但是,当我打开任务管理器观察它使用的线程时,我惊讶于该程序使用了2个线程。我不知道为什么会这样。在编译器编译程序时,我编写的程序中是否添加了某些内容? 请帮助我找出这个谜。
这是关于问题的图片。
答案 0 :(得分:1)
这可能是隐式并行的情况,您的CPU /编译器将利用指令级并行(简称ILP)来提高顺序处理器的性能。由于两个for循环彼此独立,因此编译器将使用vectorization,并且处理器将自动创建线程以缩短执行时间。因此,根据您的编译器/系统,您正在运行2个甚至4个线程。