universal-tut7 - Multicore Programming Unive& C rsal...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Multicore Programming Unive & C rsal ache Tutorial 7 CS 0368-3469 S pring 2010 He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m Sm um ary rsal rvie • Unive ove w rsal stions • Unive que achecohe ncy - MES re I •C He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 22 The m Unive ore : rsality onse rsal • C nsus is unive ad nsus build a • Fromn-thre conse e – Wait-fre arizable – Line ade ple e – n-thre d im m ntation que cifie ct – Of any se ntially spe d obje He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 3 Unive Application Part I rsal public Response apply(Invoc invoc) { int i = ThreadID.get(); Node prefer = new node(invoc); while (prefer.seq == 0) { Node before = Node.max(head); Node after = before.decideNext.decide(prefer); before.next = after; after.seq = before.seq + 1; head[i] = after; } … He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 4 Unive Application Part I I rsal ... //compute my response SeqObject MyObject = new SeqObject(); current = tail.next; while (current != prefer){ MyObject.apply(current.invoc); current = current.next; } return MyObject.apply(current.invoc); } He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 5 Wait-Fre e S liding He Window lp while (announce[i].seq == 0) { Node before = head[i]; Node help = announce[(before.seq + 1 % n)]; if (help.seq == 0) prefer = help; else prefer = announce[i]; … He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 6 Wait-fre Construction e Ptr to cell thread i wants to append announce tail i … 2 3 4 … i He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 7 1 head Sq e Thedum y nodeat thetail of thelist m is initially se to 1. t Which of thealgorithm (wait/lock-fre ), s e would ce to work corre if the ase ctly se ncenum r of thedum y nodewas que be m initially se to 0? t He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 88 Unive Obje rsal ct public class Universal { private Node head; private Node tail = new Node(); tail.seq = 1; for (int j=0; j < n; j++){ head[j] = tail } tail.seq = 0; He rlihy-S havit 2008 TheArt Multiprocessor Programming m ssor Program ing Art of of Multiproce 9 S qS e olution sn't atte e • Doe m r for Lock-Fre e • Won't work for Wait-Fre sincetheannounce array is se to thetail. t He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1010 wait-fre unive cons e rsal truction I n thewait-fre unive construction e rsal I f e thre first tries to append ach ad its own node, and the trie to he ns lp t heothe thre r ad. Explain whe r this alte Herlihy-Shavit 2008 the rnative TheArt of Multiproce Program ing ssor m 1111 Nonde rm tic te inis Proposea way to fix t heunive rsal cons truction to work for obje with cts nondeterministic sequential spe cifications. He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1212 Nonde rm tic solution te inis placewith an e quivale de rm nt te inistic obje ct. • Re r nsus obje to e node ct ach , • Add anothe conse publishing thene state w . He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1313 He ss solution adle Proposea way to avoid using dis tribute he d ad. public class Universal { private Node head; private Node tail = new Node(); tail.seq = 1; for (int j=0; j < n; j++){ head[j] = tail } He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1414 He ss solution adle Re placethecall of m with : ax() public Node last(Node tail){ Node prev = tail; Node current = prev.next; while(true){ if(current==null || current.seq==0) return prev; prev = current; current = current.next; } } He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1515 Bounde m m d e ory Proposea way to fix theunive rsal cons truction to work with bounde of d mm e ory. He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1616 Bounde m m solution d e ory ction”. • Add a “Garbagecolle fe nce xt • Updatethetail re re to ne nodethat all the he passe ads d. He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1717 MES I Modifie Exclusive S d & I nvalid d, , hare https://www.cs.tcd.ie/Jeremy.Jones/vivio/caches/MESIHelp.htm He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1818 MES I s • What is theadvantage of distinguishing Exclusiveand Modifie d? s • What is theadvantage of distinguishing Exclusiveand S d? hare He rlihy-S havit 2008 TheArt of Multiproce Program ing ssor m 1919 This work is lice d unde a C ativeC m Attribution-S Alike2.5 Lice . nse r re om ons hare nse • You are free: – to Share — to copy, distribute and transmit the work – to Remix — to adapt the work • Under the following conditions: – Attribution. You must attribute the work to “The Art of Multiprocessor Programming” (but not in any way that suggests that the authors endorse you or your use of the work). – Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. • For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to – http://creativecommons.org/licenses/by­sa/3.0/. • Any of the above conditions can be waived if you get permission from the copyright holder. He rlihy-S havit 2008 • Nothing in this license impairs or restricts the author's moral rights. Art of of Multiproce 20 TheArtMultiprocessor Programming ssor Program ing m 2020 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online