--- Tommy <[EMAIL PROTECTED]> wrote:
> Hi, > > for my app I needed a small engine that constantly resort some > data > as new one is available. I made everything in a thread and it's > > really working great, but there's something that surprises me. > > The thread is quite simple: > In the run a queue of data is processes. If the queue of data > (an > array) is empty then the thread is suspended. > To add new data I implemented a add() method that prepares and > > appends, when necessary, data to the queue. If the thread is > suspended it starts it again. > > What surprises me is that if the thread is running (still > processing > data) I can still call .add() without having to wait for the > run() to > end. It is as if the add method would be threaded as well. (a > thread > in a thread?). > > This is suppose to be normal I guess. But are there limits? Are > all > method *threaded*? If you call the .add() method from the main thread, it will run in the main thread even though it's defined in your thread subclass. The only thing that runs in a separate thread is whatever methods the .Run() event calls. Thread-to-thread communication is a little tricky (but not too much), and usually involves Semaphores (if you want to make sure the last thread execution has ended before starting the next one) or simple "watch" variables (i.e. one thread sets an integer variable to "1" when it's time for something to happen, and the other thread does a loop where it sleeps for a bit and then checks the variable to see if it's "1" yet). Mark Nutter Quick and easy regex creation and debugging! http://www.bucktailsoftware.com/products/regexplorer/ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives of this list here: <http://support.realsoftware.com/listarchives/lists.html>
