We describe Triveni, a framework and API for integrating threads and events. The design of Triveni is based on an algebra, including preemption combinators, of processes. Triveni is compatible with existing threads standards, such as Pthreads and Java thre
Triveniareprimarilyduetothedifferencesintheunder-lyingprocessalgebra.Althoughthe(asynchronous)pi-calculushasmobilechannelsandisthusquiteexpressive,itdoesnotsupportpreemptioncombinators.Ontheotherhand,infutureworkonaddingmobilitytoTriveni,wehopetobene tfromtheextensiveexperiencesgleanedfromthePictproject.TherichanalysisoftypinginthePictprojectwillberelevanttotheintegrationofTriveniwiththeextensionsofJavainspiredbytypetheory[23,1].Ourworkinheritstheideasofpreemptionandinput-enabledprocessesfromsynchronousprogramminglan-guages.(See,forinstance,[3,14,4,26].)Indeed,apor-tionofourworkisessentiallyanefforttointegrateasyn-chronousmessagepassingandsynchronousprogramming;e.g.,see[5].Incontrasttothe“globalclock”assumptionthatunderliessynchronouslanguages,Triveniallowsfullintegrationofautonomousandreactivebehaviorandsup-portsasynchronouscommunication.Areactivesystemre-spondstostimulaefromitsenvironment,whichmeansthatallsubcomponentsmustworkatapproximatelythesamegranularityofresponsetime.Autonomous/asynchronoussystemsviolatethisassumption.Thebene tsthataccruefromintegratingthesetwoparadigmsareillustratedbythetelecommunicationscasestudyof[8].Inthiscasestudy,theentirefunctionalityofthesoftwarewasimple-mentedinTriveni.Incontrast,theEsterelimplementa-tionofthesamesoftware[17]hadtorelyonexternalimplementationstorealizethefullfunctionality—e.g.,anautonomouslyevolvingtimerprocessandasynchronouscommunicationbetweenlooselycoupledcomponentsviaoperating-systemcalls.The exibilityofTrivenicomesataprice;synchronousprogramminglanguagessupportexpressiveandpowerfulnotionsofsimultaneityandpre-emption.InTriveni,weusetheslogan“instantaneousisapproximatedbyeventually+fairness”torecoversomeoftheguaranteesthatthesynchronyhypothesisprovides.LanguagessuchasAda,Amber[6],andCML[25]supportchannels,dynamicchannelandthreadcreation,andrendezvouswithselectivecommunication.Itismuchmoredif culttocompareTriveniwiththeselanguagesbe-causeinput-enablednessofprocessessigni cantlyaltersthedesigndecisions.BecauseTriveniprocessesareinput-enabled,theyaretunedtohandleevent-drivencomputa-tions,andthereisnoneedforselectiononinputasaprim-itive;weillustratethisinthefollowingsection.However,wenotethatthethedesignandimplementationofdynamicchannelcreationintheselanguageswillperforcein uencethefuturetreatmentofmobilityinTriveni.
2Example:anof cebuilding
TointroduceTriveniandillustratevariousfeaturesofTriveni,wedescribeanenvironmentalcontrolsystemforanof cebuilding.Thedesignofthissystemiscompo-
sitional;aidedbyTriveniconstructs,theimplementationre ectsthisstructure.WepostponemoreprecisedetailsofthefeaturesofTrivenitothesectionontheJavaTriveniimplementation.
Webeginwiththenotionofanof ceI/O,whichisasystemthatacceptsasinputtheeventsthatcontroltheen-vironmentofanof ce(heatingandlighting)andemitsasoutputthevariouseventsnecessarytocommunicatewiththerestoftheenvironment-controlsystem.Someoftheseemittedeventsmayoriginatefromanactionbyahumanoccupant(switchon/off,dooropen/close,andtemperaturerequest).Theremainingoutputeventisaphysicaltemper-aturereading,whichmaybeautomaticallygeneratedfromtimetotime.Of ceI/Oillustratesthedecouplingofsys-temcomponentssupportedbyTriveni.Theeventsemittedbyanof ceI/Omaybeasynchronouswiththerestofthesystem.Furthermore,anof ceI/Omaycontainitsownautonomouslyevolvingstate—e.g.,aprocessthatcontrolshowoftentemperaturereadingsareemittedbasedonhowfastthetemperatureischanging.
Athermostatpartiallyautomatesthetemperaturecon-trolofanof ce.Anof ceI/Ocombinedwithathermo-statiscalledatemperature-stableof ce.ThepseudocoderealizationinTrivenioftheseprocessesisshownbelow,alongwithadiagramgivingtheinterfaceofeachprocessintermsoftheeventsthatitemitsandaccepts.Notethatsomeeventscarrytemperaturedata.
热门文档