Comments for Scripts to Programs https://scriptstoprograms.wordpress.com PL Research, Racket, JavaScript, and more Sun, 11 May 2014 08:12:33 +0000 hourly 1 http://wordpress.com/ Comment on JavaScript: a concurrent language with shared mutable state by Javascript Concurrency https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-113 Sun, 11 May 2014 08:12:33 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-113 […] Sam Tobin-Hochstadt JavaScript: a concurrent language with shared mutable state […]

]]>
Comment on JavaScript: a concurrent language with shared mutable state by Sam Tobin-Hochstadt https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-27 Wed, 28 Sep 2011 23:46:57 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-27 In reply to Kris Kowal (@kriskowal).

I disagree with this characterization of deadlock. The Wikipedia article [1] defines it as: “A deadlock is a situation where in two or more competing actions are each waiting for the other to finish, and thus neither ever does.” This is exactly what is occurring in the dining philosophers code I gave, which is why the post describes it as deadlock.

The event loop remaining responsive is not an accomplishment — operating systems remain responsive when some of their threads deadlock as well.

[1] http://en.wikipedia.org/wiki/Deadlock

]]>
Comment on JavaScript: a concurrent language with shared mutable state by Kris Kowal (@kriskowal) https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-25 Wed, 28 Sep 2011 23:31:09 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-25 Event loop concurrency is not vulnerable to deadlock at least, which is very difficult to debug. It is vulnerable to a less insidious variant called “data-lock” wherein a program stops making progress toward a solution but the event loop remains responsive.

http://www.erights.org/talks/thesis/

]]>
Comment on Benchmarketing Racket parallelism by Sam Tobin-Hochstadt https://scriptstoprograms.wordpress.com/2011/09/25/benchmarketing/#comment-19 Wed, 28 Sep 2011 04:36:57 +0000 http://scriptstoprograms.wordpress.com/?p=39#comment-19 In reply to Javin Paul.

I talk about the performance on a quad-core in the post.

]]>
Comment on JavaScript: a concurrent language with shared mutable state by Sam Tobin-Hochstadt https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-18 Wed, 28 Sep 2011 04:32:17 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-18 In reply to Lon Ingram.

Right, if you want to do things in sequence, do them in sequence. But if you have a critical section that lasts through more than one event-loop turn, you need to use a lock, or some other synchronization construct.

]]>
Comment on JavaScript: a concurrent language with shared mutable state by Lon Ingram https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-16 Wed, 28 Sep 2011 03:19:50 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-16 First, great post! I remember the strange look I got the first time I told someone their JS code was racing.

I do think, however, that it’s worth pointing out that the semantics of setting two timeouts to fire within a short period of time* is “Do these two things, I don’t care which one you do first.” If you care about the order of the two operations, use a setTimeout chain.

I know this was a contrived example meant to serve your larger point, but wanted to make sure that random google refugees don’t wind up walking away from this post with the impression that locks are the solution to setTimeout non-determinism.

* Where ‘short period of time’ means close to the minimum timeout the browser supports

]]>
Comment on JavaScript: a concurrent language with shared mutable state by gasche https://scriptstoprograms.wordpress.com/2011/09/27/javascript-shared-state/#comment-13 Tue, 27 Sep 2011 22:10:52 +0000 http://scriptstoprograms.wordpress.com/?p=50#comment-13 Note that you don’t need shared mutable state to get deadlocks, they can happen purely during synchronization. You can get deadlocks with Erlang without Mnesia, or, trivially, with just any concurrency paradigm where you can block waiting for something to happen.

Shared mutable state is one way to implement locking, and shared state manipulations often require synchronization, so may introduce deadlocks. Otherwise, I think the main effect of shared mutable state is to make it easy to observe non-determinism, as you noted in your first code example. Deterministic concurrency models are possible when we remove shared state mutation.

I think the LtU discussion on “The Problem with Threads” touches some of these points:
http://lambda-the-ultimate.org/node/1481

]]>
Comment on Benchmarketing Racket parallelism by Sam Tobin-Hochstadt https://scriptstoprograms.wordpress.com/2011/09/25/benchmarketing/#comment-11 Tue, 27 Sep 2011 04:59:17 +0000 http://scriptstoprograms.wordpress.com/?p=39#comment-11 In reply to Stephen Bloch.

On the mandelbrot code from the shootout, now in the git repository here: https://github.com/plt/racket/blob/master/collects/tests/racket/benchmarks/shootout/mandelbrot-futures.rkt I get substantial speedups on 4 cores. What does your code say that’s it blocking on?

]]>
Comment on Benchmarketing Racket parallelism by Stephen Bloch https://scriptstoprograms.wordpress.com/2011/09/25/benchmarketing/#comment-10 Tue, 27 Sep 2011 00:19:42 +0000 http://scriptstoprograms.wordpress.com/?p=39#comment-10 Correction: on the “any-double?” examples from “Parallelism with Futures”, I DO have real-time smaller using futures than sequentially. On the mandelbrot examples, I’ve got real-time < cpu-time, but (even on the version with all fl operations) real-time is greater for the parallelized version than for the sequential version.

On the "image-processing" problems… I'm starting with 2htdp/image images, but rendering them to bitmaps before even trying to parallelize anything. Then I have one future working on (say) the top 25 pixel rows, another on the next 25 pixel rows, and so on. All the computations are completely independent; they are reported using bytes-set!, with no two futures affecting the same offset.

]]>
Comment on Benchmarketing Racket parallelism by Sam Tobin-Hochstadt https://scriptstoprograms.wordpress.com/2011/09/25/benchmarketing/#comment-9 Mon, 26 Sep 2011 16:31:29 +0000 http://scriptstoprograms.wordpress.com/?p=39#comment-9 In reply to Stephen Bloch.

By image processing, do you mean images from the 2htdp/image library? If so, they’re almost certainly not going to parallelize well with futures. The sweet spot for futures currently is programs like the mandelbrot benchmark: almost no communication, and all parallel operations are very simply (numeric computation, vector manipulation, etc).

Also, have you looked at the messages the futures library gives about what it’s blocking on?

]]>