重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
兩種情況:
創新互聯主要從事網站建設、成都網站設計、網頁設計、企業做網站、公司建網站等業務。立足成都服務解放,10余年網站建設經驗,價格優惠、服務專業,歡迎來電咨詢建站服務:18980820575
a函數或者b函數或者a、b函數在5秒內執行不完,這種情況,最好是使用多線程或者多進程;創建2個線程或者2個進程,讓a函數在一個進程(線程)執行,b函數在另外一個進程(線程)執行,5秒后調度另一個進程(線程)執行;
a,b在5秒內都能執行完成,那就在一個循環里面:先獲取執行前的機器時間,加5秒,執行完函數,再次獲取機器時間,和原機器時間加5秒,作對比,大于或者等于了,就執行另外一個函數。
#includestdio.h
#includemalloc.h
int swap (int x)
{
if(x%4==1x%5==3x%7==4)
return 1;
else return 0;
}
int main(void)
{
int i,s;
for(i=200; 200=i i=500;i++)
{
s=swap(i);
if(s==1)
printf("output:%d\n",i);
}
return 0;
}
My guess would be you are adding while loops when you press B.
From what I understand, you are not using any heap memory, cuz there is no new or malloc being called.
The size of a stack is usually 1M under Visual Studio by default, it canbe changed somewhere in the project property, and it is where you declare variables e.g
int x[10]; char c;
If you declare int x[1024*1024], which is 4MB under a 32bit system, it runs out the stack memory and results in an error, e.g. "Program stops working" and stuff.
If you want to prevent this from happening, you should actually use new or malloc cuz it gives you sufficient space on both physic memory and virtual memory on which you would never run out.
Above is just a brief explanation about stack and heap.
Can you please upload the code, especially for the part that responds to "B", otherwise it would be purely guessing and wouldn't be helpful at all.
要么你短點調試,要么你代碼貼上來,要么你分析一下你的代碼,跟著程序分析一下過程,要么就是程序運行太快調用了你沒看出來,要么就是你的程序還沒有運行到第二次調用就已經結束了。。。