Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Kaz Kylheku Newsgroups: comp.compilers Subject: Re: Question about inter-thread stack references Date: Sun, 25 Jan 2015 18:46:11 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 38 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <15-01-043@comp.compilers> References: <15-01-015@comp.compilers> <15-01-042@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: miucha.iecc.com 1422219139 40716 2001:470:1f07:1126:0:676f:7373:6970 (25 Jan 2015 20:52:19 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sun, 25 Jan 2015 20:52:19 +0000 (UTC) Keywords: parallel, comment Posted-Date: 25 Jan 2015 15:52:19 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com X-Received-Bytes: 2525 X-Received-Body-CRC: 3375462555 Xref: csiph.com comp.compilers:1500 On 2015-01-25, Joe keane wrote: > > In article <15-01-015@comp.compilers>, Ivan Godard wrote: >>If a process has two or more threads running in it, what are the rules >>regarding one thread referencing memory in a different thread's stack? > > It should be illegal, if you ask me. > > [Even if they have some way to lock and synchronize? Imagine that one > thread is acting as a server for others that put requests into a queue, > and the queue entries point to structures in the requesting thread's > stack. -John] Concretely: message_t request, reply; init_request(&request, ... args); if (send_request(other_thread, &request, &reply) == SEND_OK) { /* reply object contains reply */ } This scenario benefits from inter-thread stack access. While our thread is blocked in send_request, pointers to the request and reply objects can be directly enqueued somewhere, and the other thread can read from the request and update the reply directly. The inter-thread stack access could be avoided, but only if the API provides alternative buffers and performs copying back and forth. Anyway, it's done in the direct, efficient way in real life, whether anyone likes it or not. Unix-like kernels do it, POSIX threads programs do it, Windows threads programs do it, ... [yes, and educated fleas do it. This is a long way from compilers, unless someone's has a suggestion about how one might handle these things directly in source code. -John]