[問題] run_timer的用法

看板C_and_CPP (C/C++)作者 (早起精神好)時間13年前 (2013/02/07 00:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
第一次接觸用linux編譯的C 想請問一下 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux 問題(Question): 想要實現每隔3秒將用run_timer將一個整數值固定增加並 儲存到 _channel裡使得 lp->set_channel(_channel); 可以每3秒重新設定一次 我將 void WINGLinkStat::run_timer(Timer *) { clear_stale(); send_probe(); int _channel; int k=1; _channel = 2400+ 5*k; k++; _timer.reschedule_after_msec(3000); } void WINGLinkStat::send_probe() { wing_probe *lp = (struct wing_probe *) (p->data() + sizeof(click_ether)); lp->set_channel(_dev->channel()); } 請問這樣的寫法錯在哪? _timer 每3秒重新schedule一次使得k每3秒增加 另外_channel的值這樣能確實增加嗎? 程式碼(Code):(請善用置底文網頁, 記得排版) 摘錄處 http://codepad.org/lDXe7LxN 完整原始碼 http://codepad.org/xA4H4hx0 補充說明(Supplement): 因為我在send_probe直接改用sleep好像會使程式的值無法固定住。 所以想要用timer的方法,還是有辦法能直接改呢? 希望大家能指正我錯誤在哪 感謝各位! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.62.210
文章代碼(AID): #1H4e75jt (C_and_CPP)
文章代碼(AID): #1H4e75jt (C_and_CPP)