From: "Kurt M. Dresner" Date: 2003-07-17T02:25:40+09:00 Subject: Re: Using threads to obtain a value If the computation is just raw computation, I don't think you're going to see very much of a speedup by doing them in parallel. If they are blocking for I/O or something like that at all, then there would be an improvement, but otherwise not. Where is fetchdata getting the information from? A remote source? -Kurt On Wed, Jul 16, 2003 at 06:26:35PM +0900, Robert Klemme wrote: > > My first approach would be this: Create a condition variable and a mutex, > start all threads giving them the condition var and mutex, wait on the > condition var in the main thread. In all threads if the value is > retrieved signal the condition var. In the main thread kill all non > terminated threads (or simply let them run) and proceed. > > robert > > > > "Zachary P. Landau" schrieb im Newsbeitrag > news:e81e52a8.0307151130.5bd9ab91@posting.google.com... > > I have a few classes that all try to obtain the same data as each > > other using different methods. Each one takes around 5 seconds to get > > the data, so I'd much rather have them all try to get it at once. I > > only need the data once, from whoever gets it first. > > > > So what I would like to do is have, lets say, fetchdata() for each > > class called in a thread, and as soon as the first non-nil is returned > > from fetchdata, I want to kill the other threads and go on with the > > program. > > > > I have read the threading documentation and tried to play around a bit > > with it, but I can't seem to get it to do what I want. If someone > > could tell me how to do it or give me a point in the right direction, > > that'd be helpful. > > >======= End of Original Message =======<