全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1689
推到 Plurk!
推到 Facebook!

執行緒和主程式間的共用變數問題

答題得分者是:RaynorPao
msce
一般會員


發表:4
回覆:3
積分:1
註冊:2002-12-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-12-02 12:17:55 IP:202.39.xxx.xxx 未訂閱
想請問各位 我開了一個新的執行緒 預設是新的執行緒可以直接使用原本主程式的form1物件 那如果在主程式有一個變數,假設是int num 那可以讓新的執行緒共享主程式下的int num嗎 如果可以的話 請問要如何做呢 謝謝
------
我是新手
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-12-02 12:25:22 IP:147.8.xxx.xxx 未訂閱
Please notice that VCL is not thread safe. If you want to share the field variable, I would recommend protecting in side a critical session (this should be easier to implement than other methods). 
jessechan
版主


發表:109
回覆:394
積分:254
註冊:2002-04-05

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-12-02 17:50:17 IP:203.75.xxx.xxx 未訂閱
引言: Please notice that VCL is not thread safe. If you want to share the field variable, I would recommend protecting in side a critical session (this should be easier to implement than other methods). < face="Verdana, Arial, Helvetica"> I don't really understand why VCL is not thread safe. Could you illustrate and clarify under what kind of situation would cause this unexpected crisis. Jesse Chan
------
Jesse Chan
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-12-02 21:07:03 IP:210.3.xxx.xxx 未訂閱
引言:I don't really understand why VCL is not thread safe. Could you illustrate and clarify under what kind of situation would cause this unexpected crisis. Jesse Chan
I think that VCL was not designed for multi-thread application. Unexpected result like screen glitch, application lockup or access violation could happen RANDOMLY if you are accessing VCL (e.g. progress bar) in different threads without the use of Synchorize.
jessechan
版主


發表:109
回覆:394
積分:254
註冊:2002-04-05

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-12-02 23:49:40 IP:61.228.xxx.xxx 未訂閱
Whether should I avoid to use VCL under multi-thread environment, or, in the other hand, would you give me some advices to use safely. By the way, what you mentioned "Synchorize" is some kind of BCB mechanism or just keep all of varibles synchronized? Jesse Chan
------
Jesse Chan
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-12-03 12:28:23 IP:147.8.xxx.xxx 未訂閱
No need to aviod using VCL in thread, just be careful when using it. Synchorize is a method of TThread, which is mainly use to perform update for VCL using the main thread. Please look at the help for more details. 
jessechan
版主


發表:109
回覆:394
積分:254
註冊:2002-04-05

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-12-03 12:58:04 IP:203.75.xxx.xxx 未訂閱
引言: No need to aviod using VCL in thread, just be careful when using it. Synchorize is a method of TThread, which is mainly use to perform update for VCL using the main thread. Please look at the help for more details. < face="Verdana, Arial, Helvetica"> Got it, thanks. Jesse Chan
------
Jesse Chan
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2002-12-03 15:20:55 IP:203.73.xxx.xxx 未訂閱
引言: 我開了一個新的執行緒 預設是新的執行緒可以直接使用原本主程式的form1物件 那如果在主程式有一個變數,假設是int num 那可以讓新的執行緒共享主程式下的int num嗎 如果可以的話 請問要如何做呢
msce 你好: 如果你還是不太了解的話 請參考以下幾篇文章(有 sample code)< > > 備註: 如果覺得以上幾篇文章內容很好的話 要記得「推薦」給分~~鼓勵原作者的用心< > --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
系統時間:2024-04-24 20:08:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!