Reading this code, made me wonder what operations are actually atomic.
Anyone having a good explanation? Stephan AtomicQueueItem>makeCircular "Make a receiver circular, i.e. point to itself, answer the old value of next variable. Note, this operation should be atomic" | temp | " atomic swap here" temp := next. next := self. ^ temp |
On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: > Reading this code, made me wonder what operations are actually atomic. > Anyone having a good explanation? > > Stephan > > AtomicQueueItem>makeCircular > "Make a receiver circular, i.e. point to itself, > answer the old value of next variable. > Note, this operation should be atomic" > > | temp | > > " atomic swap here" > temp := next. > next := self. > > ^ temp > -> no back jump bytecode therefore it can not be interrupted and process switches can not happen between the statements. Marcus |
Am 14.11.2013 um 10:25 schrieb Marcus Denker <[hidden email]>: > > On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: > >> Reading this code, made me wonder what operations are actually atomic. >> Anyone having a good explanation? >> >> Stephan >> >> AtomicQueueItem>makeCircular >> "Make a receiver circular, i.e. point to itself, >> answer the old value of next variable. >> Note, this operation should be atomic" >> >> | temp | >> >> " atomic swap here" >> temp := next. >> next := self. >> >> ^ temp >> > -> no message send > -> no back jump bytecode > > therefore it can not be interrupted and process switches can not happen between the statements. Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. Norbert |
Hi Norbert,
I couldn't have said it any better. For me, this also was interesting, because I first thought: "Heck, how would I make anything atomic anyways?". And that question still stands: is there a way to make something atomic that includes message sends? I guess #critical is not the solution, is it? Joachim Am 14.11.13 11:12, schrieb Norbert Hartl: > Am 14.11.2013 um 10:25 schrieb Marcus Denker <[hidden email]>: > >> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >> >>> Reading this code, made me wonder what operations are actually atomic. >>> Anyone having a good explanation? >>> >>> Stephan >>> >>> AtomicQueueItem>makeCircular >>> "Make a receiver circular, i.e. point to itself, >>> answer the old value of next variable. >>> Note, this operation should be atomic" >>> >>> | temp | >>> >>> " atomic swap here" >>> temp := next. >>> next := self. >>> >>> ^ temp >>> >> -> no message send >> -> no back jump bytecode >> >> therefore it can not be interrupted and process switches can not happen between the statements. > Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. > > Norbert > > > -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
Am 14.11.2013 um 11:16 schrieb [hidden email]: > Hi Norbert, > > I couldn't have said it any better. For me, this also was interesting, because I first thought: "Heck, how would I make anything atomic anyways?". > And that question still stands: is there a way to make something atomic that includes message sends? I guess #critical is not the solution, is it? > No, because then it isn’t lock free anymore ;) Norbert > > Am 14.11.13 11:12, schrieb Norbert Hartl: >> Am 14.11.2013 um 10:25 schrieb Marcus Denker <[hidden email]>: >> >>> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >>> >>>> Reading this code, made me wonder what operations are actually atomic. >>>> Anyone having a good explanation? >>>> >>>> Stephan >>>> >>>> AtomicQueueItem>makeCircular >>>> "Make a receiver circular, i.e. point to itself, >>>> answer the old value of next variable. >>>> Note, this operation should be atomic" >>>> >>>> | temp | >>>> >>>> " atomic swap here" >>>> temp := next. >>>> next := self. >>>> >>>> ^ temp >>>> >>> -> no message send >>> -> no back jump bytecode >>> >>> therefore it can not be interrupted and process switches can not happen between the statements. >> Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. >> >> Norbert >> >> >> > > > -- > ----------------------------------------------------------------------- > Objektfabrik Joachim Tuchel mailto:[hidden email] > Fliederweg 1 http://www.objektfabrik.de > D-71640 Ludwigsburg http://joachimtuchel.wordpress.com > Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 > > |
Am 14.11.13 11:19, schrieb Norbert Hartl:
> Am 14.11.2013 um 11:16 schrieb [hidden email]: > >> Hi Norbert, >> >> I couldn't have said it any better. For me, this also was interesting, because I first thought: "Heck, how would I make anything atomic anyways?". >> And that question still stands: is there a way to make something atomic that includes message sends? I guess #critical is not the solution, is it? >> > No, because then it isn’t lock free anymore ;) > > Norbert But you are of course right. #critical's whole concept is locking, of course ;-) >> >> -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
In reply to this post by NorbertHartl
Note that it would be good to have a special syntactic construct for that because now
we rely on the way the compiler works to ensure such properties and it means that an accessor and a direct access are not semantically equals. Stef >> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >> >>> Reading this code, made me wonder what operations are actually atomic. >>> Anyone having a good explanation? >>> >>> Stephan >>> >>> AtomicQueueItem>makeCircular >>> "Make a receiver circular, i.e. point to itself, >>> answer the old value of next variable. >>> Note, this operation should be atomic" >>> >>> | temp | >>> >>> " atomic swap here" >>> temp := next. >>> next := self. >>> >>> ^ temp >>> >> -> no message send >> -> no back jump bytecode >> >> therefore it can not be interrupted and process switches can not happen between the statements. > > Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. > > Norbert > > |
Stef,
Am 14.11.2013 um 12:10 schrieb Stéphane Ducasse <[hidden email]>: > Note that it would be good to have a special syntactic construct for that because now > we rely on the way the compiler works to ensure such properties and it means that > an accessor and a direct access are not semantically equals. > I was asking for pointers/locations where to look at. I like to wrap my head around it in order to understand how it works and thus figuring out where and when there is a problem. Norbert > > Stef > > >>> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >>> >>>> Reading this code, made me wonder what operations are actually atomic. >>>> Anyone having a good explanation? >>>> >>>> Stephan >>>> >>>> AtomicQueueItem>makeCircular >>>> "Make a receiver circular, i.e. point to itself, >>>> answer the old value of next variable. >>>> Note, this operation should be atomic" >>>> >>>> | temp | >>>> >>>> " atomic swap here" >>>> temp := next. >>>> next := self. >>>> >>>> ^ temp >>>> >>> -> no message send >>> -> no back jump bytecode >>> >>> therefore it can not be interrupted and process switches can not happen between the statements. >> >> Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. >> >> Norbert >> >> > > |
You should look in VM code clement / eliot can reply more precisely
but the idea is to see when do you accept to suspend a computation. In Smalltlak this is after each message. Stef > Stef, > > Am 14.11.2013 um 12:10 schrieb Stéphane Ducasse <[hidden email]>: > >> Note that it would be good to have a special syntactic construct for that because now >> we rely on the way the compiler works to ensure such properties and it means that >> an accessor and a direct access are not semantically equals. >> > I was asking for pointers/locations where to look at. I like to wrap my head around it in order to understand how it works and thus figuring out where and when there is a problem. > > Norbert >> >> Stef >> >> >>>> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >>>> >>>>> Reading this code, made me wonder what operations are actually atomic. >>>>> Anyone having a good explanation? >>>>> >>>>> Stephan >>>>> >>>>> AtomicQueueItem>makeCircular >>>>> "Make a receiver circular, i.e. point to itself, >>>>> answer the old value of next variable. >>>>> Note, this operation should be atomic" >>>>> >>>>> | temp | >>>>> >>>>> " atomic swap here" >>>>> temp := next. >>>>> next := self. >>>>> >>>>> ^ temp >>>>> >>>> -> no message send >>>> -> no back jump bytecode >>>> >>>> therefore it can not be interrupted and process switches can not happen between the statements. >>> >>> Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. >>> >>> Norbert >>> >>> >> >> > > |
In reply to this post by jtuchel
Phil On Thu, Nov 14, 2013 at 11:16 AM, [hidden email] <[hidden email]> wrote: Hi Norbert, |
In reply to this post by Stéphane Ducasse
On 14 nov. 2013, at 12:38, Stéphane Ducasse <[hidden email]> wrote: > You should look in VM code clement / eliot can reply more precisely > but the idea is to see when do you accept to suspend a computation. > In Smalltlak this is after each message. Except for #== and inlined message like #ifTrue:ifFalse: , #to:do: , etc... See http://forum.world.st/About-and-td3898409.html for more details > Stef > >> Stef, >> >> Am 14.11.2013 um 12:10 schrieb Stéphane Ducasse <[hidden email]>: >> >>> Note that it would be good to have a special syntactic construct for that because now >>> we rely on the way the compiler works to ensure such properties and it means that >>> an accessor and a direct access are not semantically equals. >>> >> I was asking for pointers/locations where to look at. I like to wrap my head around it in order to understand how it works and thus figuring out where and when there is a problem. >> >> Norbert >>> >>> Stef >>> >>> >>>>> On 14 Nov 2013, at 10:15, Stephan Eggermont <[hidden email]> wrote: >>>>> >>>>>> Reading this code, made me wonder what operations are actually atomic. >>>>>> Anyone having a good explanation? >>>>>> >>>>>> Stephan >>>>>> >>>>>> AtomicQueueItem>makeCircular >>>>>> "Make a receiver circular, i.e. point to itself, >>>>>> answer the old value of next variable. >>>>>> Note, this operation should be atomic" >>>>>> >>>>>> | temp | >>>>>> >>>>>> " atomic swap here" >>>>>> temp := next. >>>>>> next := self. >>>>>> >>>>>> ^ temp >>>>>> >>>>> -> no message send >>>>> -> no back jump bytecode >>>>> >>>>> therefore it can not be interrupted and process switches can not happen between the statements. >>>> >>>> Thanks, I learn something new every day. I’ve never thought about the condition when a process switch can happen. Can you say in short when a switch of processes is checked? Because I think I won’t finding it in a reasonable time looking myself. >>>> >>>> Norbert >>>> >>>> >>> >>> >> >> > > |
In reply to this post by Stephan Eggermont-3
On 14 November 2013 10:15, Stephan Eggermont <[hidden email]> wrote: imagine that i rewrite it with following:Reading this code, made me wonder what operations are actually atomic. temp := self. temp <=> next. ^ temp here the <=> is a special 'atomic swap' operation which atomically swaps values of two variables. The best way to do that is to introduce a special bytecode in VM, which either swaps values of two temps or swaps values of temp and instance variable. If we could have such bytecode, then we would have a strong guarantee from VM about atomicity of certain operations, but since we don't have it yet, right now it is just (ab)uses the intrinsic behavior of VM, knowing that it never interrupts between two simple assignments. -- Best regards, Igor Stasenko. |
Free forum by Nabble | Edit this page |