Re: Threads......
- Posted by irvm at ellijay.com Jul 06, 2001
- 417 views
On Friday 06 July 2001 08:51, SR.Williamson wrote: > I only understood a teensie bit of any of that, but I'm going to smash > on with my questions anyway, even if they were just answered, since I > couldn't tell anyway if they *had* been answered. > > Would the programs still need to talk to each other? > > Would that be a bad thing if they did? I can imagine writing a program > that does something very simple, and having someone write another > program that uses my program to do what it does, and someone else's > program to do its thing, and then organizing and coordinating the > results. Wouldn't that be good, and open some unique possibilities for > programs? Would it be a security risk? > > Didn't someone say this could kinda be done now using the Eu sockets/TCP > library? If so, can anyone hack together an example showing me how to do > this with multiple Eu programs (even if it means I have to copy the > interpreter or bind the program) on the *same* machine? You don't really need threads to do what you have described. Semaphores, probably, so one program would know when a program it called was finished. Shared variables would be nice also, but files can often be substituted. See Pete Eberlein's remote procedure calls in the archives for an example. Threads, at least in my understanding, are most useful when you want to use the same code to do several tasks, and you would prefer that the tasks not be done sequentially. A prime example would be downloading files or pages from the internet. The routine which can download one file, can download any file. Without threads, you'd have to wait for the first one to finish before the second could begin. If there are delays in the first download, you're just wasting time waiting, time which could be used by the same routine to download the other file(s) - if you were able to thread your code. In this example, you don't really care which of the three spawned treads finishes first. In other cases, keeping track of that might be very important. In addition, every 'instance' of the thread must have it's own set of variables, (which file am I downloading, how far along am i, what to do in case of error, etc.) All non-trivial stuff. Regards, Irv