Re: [Dev-C++] how to update data constantly?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Chris M. <lor...@gm...> - 2007-12-05 22:32:54
|
On Dec 5, 2007 1:10 PM, Jessica Chen <jes...@gm...> wrote: > My whole projects have two thread. > one thread is reading RS-232 communication port. > another thread is Win32 GUI to display the data got from RS-232 > communication port. > > The design I had is: > Buttons on Win32 GUI. > So when the button is clicked, the corresponding data is read from RS232 > thread, and display in the GUI thread. > > BUT I want to have a constantly updated display. That is, there is NO > button to trigger the data update. > When the data of RS232 thread is updated, my display of GUI thread need to > be updated. > What should I design? > > My consideration for the design is: > add a constant interval timer to trigger the data update. > but how to implement it? > and do you have any other good idea? A commonly used technique is to have the GUI thread check the reader thread every X miliseconds. This requires that you use a mutex to lock the data while it's being read, otherwise you might incur the wrath of undefined behavior when reading memory that's currently being written to. What if you had a dual-core CPU, and you managed to send a read request exactly when you sent a write request? Something tells me that's not possible because of the mutexes in the lower-level implementation, but it would be interesting to see which request the memory controller disregards. I'm not sure how to implement a mutex in a Win32 thread, however, pthreads is only a wrapper on top of Win32, so it can be done (I didn't notice any special code in the pthreads sources when I glossed over them). -- Registered Linux Addict #431495 http://profile.xfire.com/mrstalinman John 3:16! If Microsoft is the Wal*Mart of the Software World, then Linux is the Home Depot |