Re: Implementation of Futures
Shiro Kawai <[email protected]> Wed, 8 Feb 2023 23:32:27 -1000
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <CALN0JNExZ6mruME0sSvW+iJBBj8uDQZo-vgELSqFm6ZYMKw8DQ@mail.gmail.com> |
Hi Glenn, Your feeling is correct. 'future' spawns a new pthread to compute the expression, and "future-get" calls thread-join! to get the result. If you create a bunch of futures, they all run in parallel. If you print something during the computation, the order you'll see the output is indeterministic---the output happens _before_ future-get anyway. If you make check-trees-of-depth return a value, and collect teh values of future-get in a list, you'll see the list is always consistent. Does this answer your question? --shiro On Wed, Feb 8, 2023 at 8:44 PM Glenn Takanishi <[email protected]> wrote: > 2023-2-8 > > Hello! > > Just curious about how futures is implemented. A short description would > suffice with respect to some code I was playing with (it's attached to this > email just for fun). > > The Gauche documentation on futures says that "future" calls code in a > separate thread (I assume a Posix pthread). So I get the feeling that a > "future" is like "pthread_create" in C. And that "future-get" can be > likened to "pthread_join". The structure of the programs between Scheme > and C look alike. > > But the output returns after "future-get" is random. The output result > from pthread_join is usally not. This is not a problem for me. I'm just > curious as to why this happens. The behavior using Guile scheme is similar > with random output results from "touch". > > This question might seem weird to you, and I apologize if so. I'm just > curious. Thanks. > > Glenn > > > _______________________________________________ > Gauche-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gauche-devel > _______________________________________________ Gauche-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gauche-devel