4 ms·
Is there some mechanism to selectively escape the protection of each thread's memory? If not, how do I communicate between threads if my application has some ki
by chrisseaton 12y ago
Is there some mechanism to selectively escape the protection of each thread's memory? If not, how do I communicate between threads if my application has some kind of shared state? Do I have to pass any messages to the main thread each time, for it to be forwarded to another parallel thread? Does that create a kind of BSP-style point where all the parallel threads stop and the main thread has to synchronise between them? How do you stop this becoming a bottleneck, and how do you load manage if all parallel threads have to stop to allow the main thread to run?
- danbruc 12y agoThere is no memory protection - all threads of a process share the same address space, the address space of the process.
- chrisseaton 12y agoThere's seven slides titled "Memory Protection" about how he changes the permission of memory pages used by different threads. If each thread has its own heap, and can't write to the global heap, how do you communicate between threads? Through the main thread? Doesn't that create a bottleneck?
- scott_s 12y agoAs chrisseaton points out, you very much can change the permissions on a processes' memory at the page level. The mprotect system call lets you change the protection on regions of memory, but you can do fancy things by unmapping memory. A friend of mine from grad school did some really elaborate tricks related to memory protection to implement runtime systems for speculation ("Exploiting Coarse-Grain Speculative Parallelism", http://www.haripyla.com/wordpress/wp-content/uploads/2012/11/OOPSLA_2011.pdf http://www.haripyla.com/wordpress/wp-content/uploads/2012/11...) and deadlock elimination (see chapters 2 and 3 of his dissertation, "Safe Concurrent Programming and Execution", http://vtechworks.lib.vt.edu/bitstream/handle/10919/19276/Pyla_HK_D_2013.pdf?sequence=1 http://vtechworks.lib.vt.edu/bitstream/handle/10919/19276/Py...).
- trentnelson 12y agoQuickly scanned both those papers -- they look very interesting, I look forward to reading both in detail.
- scott_s 12y agoThe source code is available on his website: http://www.haripyla.com/research/ http://www.haripyla.com/research/ There's also a journal article under submission which is a more consumable version of his dissertation work: http://www.haripyla.com/wordpress/wp-content/uploads/2012/11/TOPLAS_submission.pdf http://www.haripyla.com/wordpress/wp-content/uploads/2012/11...
- trentnelson 12y agoSo, I have actually spent a lot of time thinking about these exact problems, but it would have been too overwhelming to try include that information in this initial deck. I'm not even sure if I can adequately summarize it here :-) (I'm planning on covering this stuff in a subsequent presentation.) I played around with a few approaches to the things you're asking. Had good results with specialized interlocked container-type classes (e.g. xlist(); a simplified list-type object) that parallel threads could use to persist simple scalar objects (string, int, bytes). I think there's definitely room for sharing techniques that exploit the fact that threads inherently share address space -- I don't want to say that shared-nothing is the only paradigm supported and all communication must be done by message passing (like Rust?), because that's not the best solution for all problems. As for the main-thread/parallel-thread pause/run relationship... it won't be as black and white as I allude to in the deck -- the main thread will still be running, albeit with a limited memory view (i.e. you'll be restricted with what you can do in the main thread whilst parallel threads are running). Ideally, the only time all the parallel threads get paused is when global state needs to be updated by the main thread. Constantly pausing the parallel threads just because the main thread needs to do some periodic work won't be ideal. The application you're referring to... is it something that exists, or are you just using hypothetical examples? I'm always curious to hear of architectures where threads need to constantly talk to each other in order for work to get done -- does your app fit this bill?
- chrisseaton 12y agoI'm just talking theory, but there is a whole class of applications that are very difficult to express without any shared state, or state shared by relative expensive message passing. The Lonestar benchmark suite from Texas includes good examples http://iss.ices.utexas.edu/?p=projects/galois/lonestar http://iss.ices.utexas.edu/?p=projects/galois/lonestar.
- trentnelson 12y agoThanks for the pointer to Lonestar, I'll review. (PDF link to the relevant paper: http://iss.ices.utexas.edu/Publications/Papers/ispass2009.pdf http://iss.ices.utexas.edu/Publications/Papers/ispass2009.pd...) Re: target problems... the catalyst behind PyParallel can ultimately be tied back to the discussions on python-ideas@ in Sept/Oct 2012 that led to Python 3.4's asyncio. I wanted to show that, hey, there's a different way you can approach async I/O that, when paired with better kernel I/O primitives, actually allows you to exploit parallelism too (i.e. use all my cores). I'm particularly interested in problems that are both I/O-bound (or driven) and compute heavy, which is common in the enterprise. The parallel aspect of PyParallel is an area I'm still flushing out (I wanted to get the async stuff working first, and I'm happy with the results). I definitely want to spend the next sprint focusing on using PyParallel for parallel computation problems, where you typically go from sequential execution, fan out to parallel compute, then fan back in to sequential execution. This is common with aggregation-oriented "parallel data" problems. I'm definitely less familiar with problems that inherently require a lot of cross-talk between threads, like the agglomerative clustering referred to in that paper linked above. Now, all that being said, I did have some good results simply wrapping Windows' synchronization primitives (http://msdn.microsoft.com/en-us/library/windows/desktop/ms686360.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms68...) and exposing via Python: http://hg.python.org/sandbox/trent/file/0e70a0caa1c0/Lib/async/test/test_primitives.py#l427 http://hg.python.org/sandbox/trent/file/0e70a0caa1c0/Lib/asy... Things like `async.signal_and_wait(object1, object2)` are actually pretty darn useful. Again, it's thanks to the vibrant set of synchronization primitives provided by Windows.