Alex Cole University of Leicester CPA 2012, Dundee 26 th - - PowerPoint PPT Presentation

alex cole university of leicester cpa 2012 dundee 26 th
SMART_READER_LITE
LIVE PREVIEW

Alex Cole University of Leicester CPA 2012, Dundee 26 th - - PowerPoint PPT Presentation

Alex Cole University of Leicester CPA 2012, Dundee 26 th 29 th August Alistair A McEwan Geoff Mainland University of Leicester MicrosoF Research


slide-1
SLIDE 1

Alex ¡Cole ¡ University ¡of ¡Leicester ¡ CPA ¡2012, ¡Dundee ¡ 26th ¡– ¡29th ¡August ¡

Alistair ¡A ¡McEwan ¡ University ¡of ¡Leicester ¡ Geoff ¡Mainland ¡ MicrosoF ¡Research ¡

slide-2
SLIDE 2

par ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Process2(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Process3(); ¡ } ¡

slide-3
SLIDE 3

#define ¡par ¡\ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡( ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._ParStart(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._LoopCheck(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._LoopEnd()) ¡ __declspec((thead)) ¡CSPPP ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD; ¡

slide-4
SLIDE 4

class ¡CSPPP ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡std::stack<CSPPPScope ¡*> ¡m_scope; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡bool ¡m_loop; ¡ ¡ ¡ ¡ ¡ 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 ¡ ¡ ¡ ¡ ¡void ¡Add(_Process ¡* ¡p) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡m_children.add(p); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-9
SLIDE 9

void ¡Run() ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡Not ¡C++ ¡(for). ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡foreach ¡(_Process ¡* ¡c ¡: ¡m_children) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_ ¡CSPPP_CURRENT_THREAD ¡.Schedule(c); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_Yield(); ¡ } ¡

slide-10
SLIDE 10

par ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process2(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡seq ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process3(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process4(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-11
SLIDE 11

#define ¡par ¡\ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡( ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._SeqStart(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._LoopCheck(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡_CSPPP_CURRENT_THREAD._LoopEnd()) ¡

slide-12
SLIDE 12

class ¡SeqScope ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡void ¡Add(_Process ¡* ¡p) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡p-­‑>_Run(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡delete ¡p; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡void ¡Run() ¡{} ¡ } ¡

slide-13
SLIDE 13

chan ¡int ¡c1; ¡ par ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process2(c1); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡seq ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process3(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process4(c1); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-14
SLIDE 14

Chan<int> ¡c1; ¡ par ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process2(c1); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡seq ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process3(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡proc ¡Process4(c1); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-15
SLIDE 15

int ¡var ¡= ¡*chan; ¡ *chan ¡= ¡42; ¡ class ¡Chan ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ChanAccess ¡& ¡operator* ¡() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡m_access; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-16
SLIDE 16

class ¡Chan<T> ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ChanAccess<T> ¡& ¡operator* ¡() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡m_access; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-17
SLIDE 17

class ¡ChanAccess<T> ¡ { ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡operator ¡T() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡ReadChannel(m_parent); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡}; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ChanAccess<T> ¡& ¡operator=(T ¡& ¡d) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡WriteChannel(m_parent, ¡d); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡*this; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-18
SLIDE 18
  • No ¡working ¡scheduler ¡
  • Crashes ¡randomly ¡(possibly ¡data ¡races) ¡
  • Alternate ¡exishng ¡backend ¡
slide-19
SLIDE 19

?