Re: [racket-users] Thread and filesystem watching

2017-01-26 Thread David Storrs
Thanks for the help, everyone. This works great. I especially like handle-evt -- I had seen it in the Reference when I was reading about events but didn't understand what it did. It really makes this easy. On Wed, Jan 25, 2017 at 8:17 PM, Jon Zeppieri wrote: > On Wed, Jan 25, 2017 at 8:03 P

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread Jon Zeppieri
On Wed, Jan 25, 2017 at 8:03 PM, Matthew Flatt wrote: > > The `handle-evt` constructor does that. > > For example, this loop will print "one" or "two" pseudorandomly, depending on > whether the first or second semaphore is chosen: > > (let loop () >(define e1 > (handle-evt (make-semaphor

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread Robby Findler
FWIW, this is an instance of a very useful pattern (that DrRacket uses all over the place). You make a loop that syncs on a bunch of different events, each of which updates some (thread-local (usually in arguments)) state and then goes back into the loop, possibly after doing some communication to

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread Jon Zeppieri
On Wed, Jan 25, 2017 at 7:34 PM, David Storrs wrote: > > > After trying this out I see there's a problem: if you apply sync to all of > them simultaneously there is no way to distinguish which directory it was > that changed. By spawning a separate thread for each one I can close over > the r

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread Matthew Flatt
At Wed, 25 Jan 2017 19:34:08 -0500, David Storrs wrote: > After trying this out I see there's a problem: if you apply sync to all of > them simultaneously there is no way to distinguish which directory it was > that changed. By spawning a separate thread for each one I can close over > the releva

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread David Storrs
On Tue, Jan 24, 2017 at 7:26 PM, Jon Zeppieri wrote: > Hi David, > > On Tue, Jan 24, 2017 at 6:52 PM, David Storrs > wrote: > >> [snip] >> >> - When I create the 'monitor this' event, I will need to wrap the sync in >>> a thread since (sync) is synchronous. >> >> >> >> If I understand you correc

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread David Storrs
Thanks, Matthew. That's reassuring. On Wed, Jan 25, 2017 at 8:20 AM, Matthew Flatt wrote: > At Tue, 24 Jan 2017 18:52:43 -0500, David Storrs wrote: > > 1) How do I determine what a safe maximum number of threads is? > > For a typical program, 10k or so is probably safe. > > The program below cr

Re: [racket-users] Thread and filesystem watching

2017-01-25 Thread Matthew Flatt
At Tue, 24 Jan 2017 18:52:43 -0500, David Storrs wrote: > 1) How do I determine what a safe maximum number of threads is? For a typical program, 10k or so is probably safe. The program below creates 10k threads. On my machine, it allocates about 200M of memory with a peak memory use of 160MB. --

Re: [racket-users] Thread and filesystem watching

2017-01-24 Thread David Storrs
On Tue, Jan 24, 2017 at 7:26 PM, Jon Zeppieri wrote: > Hi David, > > On Tue, Jan 24, 2017 at 6:52 PM, David Storrs > wrote: > >> [snip] >> >> - When I create the 'monitor this' event, I will need to wrap the sync in >>> a thread since (sync) is synchronous. >> >> >> >> If I understand you correc

Re: [racket-users] Thread and filesystem watching

2017-01-24 Thread Jon Zeppieri
Hi David, On Tue, Jan 24, 2017 at 6:52 PM, David Storrs wrote: > [snip] > > - When I create the 'monitor this' event, I will need to wrap the sync in >> a thread since (sync) is synchronous. > > > > If I understand you correctly, you're considering creating a separate thread for each directory t

[racket-users] Thread and filesystem watching

2017-01-24 Thread David Storrs
I mentioned before that I'm writing a system to watch the filesystem for changes. I'm finishing that up and I have a few questions about concurrency issues. 1) How do I determine what a safe maximum number of threads is? 2) I think that (fold-files) is the best way to walk a directory tree, sin