我目前正在尝试将当前运行的线程限制为最大值,例如核心数量.
这一切都做得很好,我每秒有100次完整的数据写入(打开,追加,关闭),但是当不使用信号量作为互斥量(数量> 1)时,订单或写入访问就是伪装的.
使用for循环:
for(int i=0;i<10;i++)
mywrite.writeasnewthread("test.txt","asd"+mywrite.tostring(i));
Run Code Online (Sandbox Code Playgroud)
其中writeasnewthread包含
WaitForSingleObject(this->semaphor,INFINITE);
CreateThread(NULL,0,&threadwrite,(void*)param,0,NULL);
Run Code Online (Sandbox Code Playgroud)
用threadwrite新的线程,包含名称,数据和信号量的param.然后在最后我写的threadwrite中
ReleaseSemaphore(writeparam->This->semaphor,1,NULL);
Run Code Online (Sandbox Code Playgroud)
但是,当我查看我在threadwrite中编写的文件时,会有类似的东西
2013-5-16 14:41:25 asd0
2013-5-16 14:41:25 asd3
2013-5-16 14:41:25 asd5
2013-5-16 14:41:25 asd7
2013-5-16 14:41:25 asd1
2013-5-16 14:41:25 asd8
2013-5-16 14:41:25 asd9
2013-5-16 14:41:25 asd6
2013-5-16 14:41:25 asd4
2013-5-16 14:41:25 asd2
Run Code Online (Sandbox Code Playgroud)
我可能有一些基本的误解,信号量是如何工作的,但我虽然线程会等待信号量再次有一个空闲插槽然后继续工作......
那么,有一种保存文件顺序的好方法吗?或者这会破坏信号量的概念?
问候,朱利安
我尝试使用Range-header在Greasemonkey脚本中发送请求.请求的网站有点长,我知道我实际需要哪些部分,所以我想,而不是要求整个网站下载我可以请求必要的500字节来加快速度.
但是,Range: bytes=0-500总是给我完整的网站.我也试过了Content-Range: bytes=0-500,但是不起作用,Content-Length:500由于安全问题,不允许再设置它.
那么,有谁知道,为什么会这样?我正在使用Greasemonkey脚本:
GM_xmlhttpRequest({
method: 'GET',
url: "http://colonel-strawberry.deviantart.com/",
headers: {"Range": "bytes=0-500"},
onload: function (responseDetails) {
console.log(responseDetails);
},
onerror: function(responseDetails) {
console.log("err:"+responseDetails);
}
});
Run Code Online (Sandbox Code Playgroud)
使用response-header:
Date: Mon, 05 Nov 2012 17:11:42 GMT
Content-Encoding: gzip
Transfer-Encoding: chunked
P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR CURa OUR STP"
Connection: Keep-Alive
Server: Apache
Vary: Accept-Encoding
Content-Type: text/html
Cache-Control: private
Keep-Alive: timeout=45
Run Code Online (Sandbox Code Playgroud)