Changeset 22bdc34
- Timestamp:
- Apr 23, 2018, 10:08:51 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- de6319f
- Parents:
- e6d39fe (diff), c8ad5d9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/Paper.tex
re6d39fe r22bdc34 19 19 \usepackage{listings} % format program code 20 20 \usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig} 21 \renewcommand{\thesubfigure}{(\alph{subfigure})} 21 \renewcommand{\thesubfigure}{(\Alph{subfigure})} 22 \captionsetup{justification=raggedright,singlelinecheck=false} 22 23 \usepackage{siunitx} 23 24 \sisetup{ binary-units=true } … … 98 99 \newcommand{\abbrevFont}{\textit} % set empty for no italics 99 100 \@ifundefined{eg}{ 100 \newcommand{\EG}{\abbrevFont{e} .\abbrevFont{g}.}101 \newcommand{\EG}{\abbrevFont{e}\abbrevFont{g}} 101 102 \newcommand*{\eg}{% 102 103 \@ifnextchar{,}{\EG}% … … 105 106 }}{}% 106 107 \@ifundefined{ie}{ 107 \newcommand{\IE}{\abbrevFont{i} .\abbrevFont{e}.}108 \newcommand{\IE}{\abbrevFont{i}\abbrevFont{e}} 108 109 \newcommand*{\ie}{% 109 110 \@ifnextchar{,}{\IE}% … … 143 144 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__, 144 145 auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__, 145 coroutine, disable, dtype, enable, __extension__, exception, fallthrough, fallthru, finally,146 coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally, 146 147 __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__, 147 148 inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or, … … 169 170 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1 170 171 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 171 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0. 5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,172 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2, 172 173 moredelim=**[is][\color{red}]{`}{`}, 173 174 }% lstset … … 216 217 \author[1]{Thierry Delisle} 217 218 \author[1]{Peter A. Buhr*} 218 \authormark{ Thierry Delisle \textsc{et al}}219 220 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{ Ontario}, \country{Canada}}}221 222 \corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}223 \presentaddress{Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada} 224 219 \authormark{DELISLE \textsc{et al.}} 220 221 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Waterloo, ON}, \country{Canada}}} 222 223 \corres{*Peter A. Buhr, Cheriton School of Computer Science, University of Waterloo, 200 University Avenue West, Waterloo, ON, N2L 3G1, Canada. \email{pabuhr{\char`\@}uwaterloo.ca}} 224 225 \fundingInfo{Natural Sciences and Engineering Research Council of Canada} 225 226 226 227 \abstract[Summary]{ 227 228 \CFA is a modern, polymorphic, \emph{non-object-oriented} extension of the C programming language. 228 229 This paper discusses the design of the concurrency and parallelism features in \CFA, and the concurrent runtime-system. 229 These features are created from scratch as ISO C lacks concurrency, relying largely on pthreads .230 These features are created from scratch as ISO C lacks concurrency, relying largely on pthreads library. 230 231 Coroutines and lightweight (user) threads are introduced into the language. 231 232 In addition, monitors are added as a high-level mechanism for mutual exclusion and synchronization. … … 255 256 Examples of high-level approaches are task based~\cite{TBB}, message passing~\cite{Erlang,MPI}, and implicit threading~\cite{OpenMP}. 256 257 257 This paper use dthe following terminology.258 This paper uses the following terminology. 258 259 A \newterm{thread} is a fundamental unit of execution that runs a sequence of code and requires a stack to maintain state. 259 Multiple simultaneous threads give srise to \newterm{concurrency}, which requires locking to ensure safe communication and access to shared data.260 Multiple simultaneous threads give rise to \newterm{concurrency}, which requires locking to ensure safe communication and access to shared data. 260 261 % Correspondingly, concurrency is defined as the concepts and challenges that occur when multiple independent (sharing memory, timing dependencies, \etc) concurrent threads are introduced. 261 262 \newterm{Locking}, and by extension locks, are defined as a mechanism to prevent progress of threads to provide safety. 262 263 \newterm{Parallelism} is running multiple threads simultaneously. 263 264 Parallelism implies \emph{actual} simultaneous execution, where concurrency only requires \emph{apparent} simultaneous execution. 264 As such, parallelism is only observable in differences in performance, which is observed through differences in timing.265 As such, parallelism only affects performance, which is observed through differences in space and/or time. 265 266 266 267 Hence, there are two problems to be solved in the design of concurrency for a programming language: concurrency and parallelism. 267 While these two concepts are often combined, they are in factdistinct, requiring different tools~\cite[\S~2]{Buhr05a}.268 While these two concepts are often combined, they are distinct, requiring different tools~\cite[\S~2]{Buhr05a}. 268 269 Concurrency tools handle synchronization and mutual exclusion, while parallelism tools handle performance, cost and resource utilization. 269 270 … … 278 279 279 280 The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency. 280 281 \CFA is an extension of ISO-C and therefore supports all of the same paradigms as C. 282 It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opted out easily. 281 Most of the following code examples can be found on the \CFA website~\cite{Cforall}. 282 283 \CFA is an extension of ISO-C, and therefore, supports all of the same paradigms as C. 284 %It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opted out easily. 283 285 Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code. 284 286 The vast majority of the code produced by the \CFA translator respects memory layouts and calling conventions laid out by C. 285 Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (\eg {\tt this}), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent287 Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (\eg @this@) and inheritance, it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent 286 288 values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects. 287 Most of the following code examples can be found on the \CFA website~\cite{Cforall}.288 289 289 290 … … 293 294 In regards to concurrency, the semantic difference between pointers and references are not particularly relevant, but since this document uses mostly references, here is a quick overview of the semantics: 294 295 \begin{cfa} 295 int x, *p1 = &x, **p2 = &p1, ***p3 = &p2, 296 &r1 = x, &&r2 = r1, &&&r3 = r2; 297 ***p3 = 3; $\C{// change x}$ 298 r3 = 3; $\C{// change x, ***r3}$ 299 **p3 = ...; $\C{// change p1}$ 300 *p3 = ...; $\C{// change p2}$ 301 int y, z, & ar[3] = {x, y, z}; $\C{// initialize array of references}$ 302 typeof( ar[1]) p; $\C{// is int, referenced object type}$ 303 typeof(&ar[1]) q; $\C{// is int \&, reference type}$ 304 sizeof( ar[1]) == sizeof(int); $\C{// is true, referenced object size}$ 305 sizeof(&ar[1]) == sizeof(int *); $\C{// is true, reference size}$ 296 int x, y, z; 297 int * p1 = &x, ** p2 = &p1, *** p3 = &p2, $\C{// pointers to x}$ 298 & r1 = x, && r2 = r1, &&& r3 = r2; $\C{// references to x}$ 299 300 *p1 = 3; **p2 = 3; ***p3 = 3; $\C{// change x}$ 301 r1 = 3; r2 = 3; r3 = 3; $\C{// change x}$ 302 **p3 = &y; *p3 = &z; $\C{// change p1, p2}$ 303 &&r3 = &y; &r3 = &z; $\C{// change p1, p2}$ 304 int & ar[3] = {x, y, z}; $\C{// initialize array of references}$ 305 306 typeof( ar[1]) p; $\C{// is int, referenced object type}$ 307 typeof(&ar[1]) q; $\C{// is int \&, reference type}$ 308 sizeof( ar[1]) == sizeof(int); $\C{// is true, referenced object size}$ 309 sizeof(&ar[1]) == sizeof(int *); $\C{// is true, reference size}$ 306 310 \end{cfa} 307 311 The important take away from this code example is that a reference offers a handle to an object, much like a pointer, but which is automatically dereferenced for convenience. … … 626 630 \end{lrbox} 627 631 \subfloat[3 States, internal variables]{\label{f:Coroutine3States}\usebox\myboxA} 628 \qquad 632 \qquad\qquad 629 633 \subfloat[1 State, internal variables]{\label{f:Coroutine1State}\usebox\myboxB} 630 634 \caption{\CFA Coroutine Fibonacci Implementations} … … 653 657 654 658 \begin{figure} 655 \centering 656 \begin{cfa} 659 \begin{cfa}[xleftmargin=4\parindentlnth] 657 660 `coroutine` Format { 658 661 char ch; $\C{// used for communication}$ -
doc/papers/general/Paper.tex
re6d39fe r22bdc34 1 \documentclass[AMA,STIX1COL,STIXSMALL]{WileyNJD-v2} 1 \documentclass[AMA,STIX1COL]{WileyNJD-v2} 2 2 3 \articletype{RESEARCH ARTICLE}% 3 4 … … 17 18 \usepackage{upquote} % switch curled `'" to straight 18 19 \usepackage{listings} % format program code 20 \captionsetup{justification=raggedright,singlelinecheck=false} 19 21 %\usepackage{enumitem} 20 22 %\setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global … … 27 29 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 28 30 29 \lefthyphenmin= 4% hyphen only after 4 characters30 \righthyphenmin= 431 \lefthyphenmin=3 % hyphen only after 4 characters 32 \righthyphenmin=3 31 33 32 34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 86 88 \newcommand{\abbrevFont}{\textit} % set empty for no italics 87 89 \@ifundefined{eg}{ 88 \newcommand{\EG}{\abbrevFont{e} .\abbrevFont{g}.}90 \newcommand{\EG}{\abbrevFont{e}\abbrevFont{g}} 89 91 \newcommand*{\eg}{% 90 92 \@ifnextchar{,}{\EG}% … … 93 95 }}{}% 94 96 \@ifundefined{ie}{ 95 \newcommand{\IE}{\abbrevFont{i} .\abbrevFont{e}.}97 \newcommand{\IE}{\abbrevFont{i}\abbrevFont{e}} 96 98 \newcommand*{\ie}{% 97 99 \@ifnextchar{,}{\IE}% … … 129 131 \lstdefinelanguage{CFA}[ANSI]{C}{ 130 132 morekeywords={ 131 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, _At, __attribute, 132 __attribute__, auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, 133 __const, __const__, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, 134 finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t, 135 otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof, 136 __typeof__, virtual, with, zero_t}, 137 morekeywords=[2]{ 138 _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex, or, 139 resume, suspend, thread, _Thread_local, waitfor, when, yield}, 133 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__, 134 auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__, 135 coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally, 136 __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__, 137 inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or, 138 otype, restrict, __restrict, __restrict__, __signed, __signed__, _Static_assert, thread, 139 _Thread_local, throw, throwResume, timeout, trait, try, ttype, typeof, __typeof, __typeof__, 140 virtual, __volatile, __volatile__, waitfor, when, with, zero_t}, 140 141 moredirectives={defined,include_next}% 141 142 } … … 158 159 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1 159 160 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 160 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0. 5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,161 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2, 161 162 moredelim=**[is][\color{red}]{`}{`}, 162 163 }% lstset … … 180 181 \authormark{MOSS \textsc{et al}} 181 182 182 \address[1]{\orgdiv{ David R. Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Ontario}, \country{Canada}}}183 184 \corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}185 \presentaddress{David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada} 186 183 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Waterloo, ON}, \country{Canada}}} 184 185 \corres{*Peter A. Buhr, Cheriton School of Computer Science, University of Waterloo, 200 University Avenue West, Waterloo, ON, N2L 3G1, Canada. \email{pabuhr{\char`\@}uwaterloo.ca}} 186 187 \fundingInfo{Natural Sciences and Engineering Research Council of Canada} 187 188 188 189 \abstract[Summary]{ … … 228 229 Nevertheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive. 229 230 230 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C while maintaining both source compatibility with C and a familiar programming model for programmers.231 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C, while maintaining both source and runtime compatibility with C and a familiar programming model for programmers. 231 232 The four key design goals for \CFA~\cite{Bilson03} are: 232 233 (1) The behaviour of standard C code must remain the same when translated by a \CFA compiler as when translated by a C compiler; … … 328 329 A simple example is leveraging the existing type-unsafe (@void *@) C @bsearch@ to binary search a sorted float array: 329 330 \begin{cfa} 330 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, 331 int (* compar)( const void *, const void * )); 331 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (* compar)( const void *, const void * )); 332 332 int comp( const void * t1, const void * t2 ) { 333 333 return *(double *)t1 < *(double *)t2 ? -1 : *(double *)t2 < *(double *)t1 ? 1 : 0; … … 336 336 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$ 337 337 \end{cfa} 338 which can be augmented simply with ageneralized, type-safe, \CFA-overloaded wrappers:338 which can be augmented simply with generalized, type-safe, \CFA-overloaded wrappers: 339 339 \begin{cfa} 340 340 forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) { … … 398 398 T ?++( T * ); 399 399 }; 400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) { // use trait400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {$\C{// use trait}$ 401 401 `T` total = { `0` }; $\C{// instantiate T from 0 by calling its constructor}$ 402 402 for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$ … … 576 576 return (scalar(U)){ a.value + b.value }; 577 577 } 578 scalar(metres) half_marathon = { 21 093 };579 scalar(litres) swimming_pool = { 2 500000 };578 scalar(metres) half_marathon = { 21_093 }; 579 scalar(litres) swimming_pool = { 2_500_000 }; 580 580 scalar(metres) marathon = half_marathon + half_marathon; 581 581 scalar(litres) two_pools = swimming_pool + swimming_pool; … … 724 724 \end{cfa} 725 725 Here, the mass assignment sets all members of @s@ to zero. 726 Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member 726 Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member-tuple expressions to manually restructure a tuple (\eg rearrange, drop, and duplicate components). 727 727 \begin{cfa} 728 728 [int, int, long, double] x; … … 1879 1879 \lstDeleteShortInline@% 1880 1880 \begin{tabular}{@{}l@{\hspace{3em}}l|l@{}} 1881 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}} & \multicolumn{1}{c }{\textbf{C Implicit Hoisting}} & \multicolumn{1}{|c}{\textbf{\CFA}} \\1881 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}} & \multicolumn{1}{c|}{\textbf{C Implicit Hoisting}} & \multicolumn{1}{c}{\textbf{\CFA}} \\ 1882 1882 \hline 1883 1883 \begin{cfa} … … 2002 2002 { 2003 2003 VLA x, y = { 20, 0x01 }, z = y; $\C{// z points to y}$ 2004 // ?{}( x ); ?{}( y, 20, 0x01 );?{}( z, y );2004 // ?{}( x ); ?{}( y, 20, 0x01 ); ?{}( z, y ); 2005 2005 ^x{}; $\C{// deallocate x}$ 2006 2006 x{}; $\C{// reallocate x}$ … … 2027 2027 These semantics closely mirror the rule for implicit declaration of constructors in \CC\cite[p.~186]{ANSI98:C++}. 2028 2028 2029 In some circumstance programmers may not wish to have constructor and destructor calls. 2030 In these cases, \CFA provides the initialization syntax \lstinline|S x @= {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated. 2031 Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics. 2029 In some circumstance programmers may not wish to have implicit constructor and destructor generation and calls. 2030 In these cases, \CFA provides the initialization syntax \lstinline|S x `@=` {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated. 2031 Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics. 2032 The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal. 2032 2033 The point of \lstinline|@=| is to provide a migration path from legacy C code to \CFA, by providing a mechanism to incrementally convert to implicit initialization. 2033 2034 … … 2054 2055 \begin{cfa} 2055 2056 20_`hh` // signed char 2056 21_`hh`u 2057 21_`hh`u // unsigned char 2057 2058 22_`h` // signed short int 2058 2059 23_u`h` // unsigned short int 2059 24`z` // size_t2060 24`z` // size_t 2060 2061 \end{cfa} 2061 2062 & … … 2088 2089 To provide this precision, \CFA introduces a new type @zero_t@ as the type of literal @0@ (somewhat analagous to @nullptr_t@ and @nullptr@ in \CCeleven); 2089 2090 @zero_t@ can only take the value @0@, but has implicit conversions to the integer and pointer types so that C code involving @0@ continues to work. 2090 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ( (x) != 0)@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?(T, zero_t)@.2091 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ( (x) != 0 )@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?( T, zero_t )@. 2091 2092 \CC makes types truthy by adding a conversion to @bool@; 2092 2093 prior to the addition of explicit cast operators in \CCeleven, this approach had the pitfall of making truthy types transitively convertable to any numeric type; … … 2163 2164 \lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}} 2164 2165 \lstDeleteShortInline@% 2165 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2166 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\2166 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2167 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2167 2168 \begin{cfa} 2168 2169 struct W { … … 2260 2261 \begin{cfa} 2261 2262 MIN 2262 2263 2263 MAX 2264 2265 2264 PI 2266 2265 E … … 2268 2267 & 2269 2268 \begin{cfa} 2270 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, 2271 FLT_MIN, DBL_MIN, LDBL_MIN 2272 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, 2273 FLT_MAX, DBL_MAX, LDBL_MAX 2269 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN 2270 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX 2274 2271 M_PI, M_PIl 2275 2272 M_E, M_El … … 2444 2441 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2445 2442 ip = (int *)realloc( ip, 2 * dim * sizeof( int ) ); 2446 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); 2447 memset( ip, fill, 4 * dim * sizeof( int ) ); 2443 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) ); 2444 2448 2445 ip = memalign( 16, sizeof( int ) ); 2449 2446 ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) ); -
src/Common/utility.h
re6d39fe r22bdc34 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 19 16:21:44201813 // Update Count : 3 712 // Last Modified On : Fri Apr 20 22:35:33 2018 13 // Update Count : 38 14 14 // 15 15 … … 437 437 438 438 // ----------------------------------------------------------------------------- 439 // O(1) polymorphic integer log2, using clz, which returns the number of leading 0-bits, starting at the most439 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most 440 440 // significant bit (single instruction on x86) 441 441 442 442 template<typename T> 443 inline constexpr T log2(const T & t) {443 inline constexpr T ilog2(const T & t) { 444 444 if ( std::is_integral<T>::value ) { 445 445 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1; … … 449 449 } // if 450 450 return -1; 451 } 451 } // ilong2 452 452 453 453 -
src/Parser/DeclarationNode.cc
re6d39fe r22bdc34 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 19 15:09:29201813 // Update Count : 106 212 // Last Modified On : Fri Apr 20 22:37:20 2018 13 // Update Count : 1063 14 14 // 15 15 … … 562 562 checkQualifiers( type, q->type ); 563 563 if ( (builtin == Zero || builtin == One) && error.length() == 0 ) { 564 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ log2( q->type->qualifiers.val )], builtinTypeNames[builtin] );564 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )], builtinTypeNames[builtin] ); 565 565 // appendError( error, string( "questionable qualifiers" ) ); 566 566 } // if -
src/tests/concurrent/examples/boundedBufferEXT.c
re6d39fe r22bdc34 8 8 // Created On : Wed Apr 18 22:52:12 2018 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Wed Apr 18 22:56:17201811 // Update Count : 210 // Last Modified On : Fri Apr 20 22:25:14 2018 11 // Update Count : 6 12 12 // 13 13 … … 20 20 //Duration default_preemption() { return 0; } 21 21 22 enum { BufferSize = 5 };22 enum { BufferSize = 50 }; 23 23 24 24 forall( otype T ) … … 33 33 forall( otype T ) 34 34 int query( Buffer(T) & buffer ) { return buffer.count; } 35 36 forall( otype T ) // forward 37 T remove( Buffer(T) & mutex buffer ); 35 38 36 39 forall( otype T ) -
src/tests/concurrent/examples/boundedBufferINT.c
re6d39fe r22bdc34 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Tue Jan 2 12:18:18 201811 // Update Count : 3310 // Last Modified On : Fri Apr 20 22:18:18 2018 11 // Update Count : 78 12 12 // 13 13 14 #include <stdlib> 15 #include <fstream> // random14 #include <stdlib> // random 15 #include <fstream> 16 16 #include <kernel> 17 17 #include <thread> 18 18 #include <unistd.h> // getpid 19 19 20 //Duration default_preemption() { return 0; } 21 22 enum { BufferSize = 50 }; 23 24 forall( otype T ) 20 25 monitor Buffer { 21 26 condition full, empty; 22 27 int front, back, count; 23 int elements[20];28 T elements[BufferSize]; 24 29 }; 25 30 26 void ?{}( Buffer & buffer ) { 27 buffer.front = buffer.back = buffer.count = 0; 28 } 31 forall( otype T ) 32 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; } 29 33 30 int query( Buffer & buffer ) { return buffer.count; } 34 forall( otype T ) 35 int query( Buffer(T) & buffer ) { return buffer.count; } 31 36 32 void insert( Buffer & mutex buffer, int elem ) with( buffer ) { 33 if ( count == 20 ) wait( empty ); 37 forall( otype T ) 38 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 39 if ( count == BufferSize ) wait( empty ); 34 40 elements[back] = elem; 35 back = ( back + 1 ) % 20;41 back = ( back + 1 ) % BufferSize; 36 42 count += 1; 37 43 signal( full ); 38 44 } 39 45 40 int remove( Buffer & mutex buffer ) with( buffer ) { 46 forall( otype T ) 47 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 41 48 if ( count == 0 ) wait( full ); 42 intelem = elements[front];43 front = ( front + 1 ) % 20;49 T elem = elements[front]; 50 front = ( front + 1 ) % BufferSize; 44 51 count -= 1; 45 52 signal( empty ); … … 47 54 } 48 55 56 const int Sentinel = -1; 57 49 58 thread Producer { 50 Buffer & buffer;59 Buffer(int) & buffer; 51 60 unsigned int N; 52 61 }; 53 void main( Producer & prod ) {54 for ( int i = 1; i <= prod.N; i += 1 ) {62 void main( Producer & prod ) with( prod ) { 63 for ( int i = 1; i <= N; i += 1 ) { 55 64 yield( random( 5 ) ); 56 insert( prod.buffer, 1 );65 insert( buffer, 1 ); 57 66 } // for 58 insert( prod.buffer, -1 );59 67 } 60 void ?{}( Producer & prod, Buffer * buffer, unsignedint N ) {68 void ?{}( Producer & prod, Buffer(int) * buffer, int N ) { 61 69 &prod.buffer = buffer; 62 70 prod.N = N; … … 64 72 65 73 thread Consumer { 66 Buffer & buffer;67 int & sum; // summation of producer values74 Buffer(int) & buffer; 75 int & sum; // summation of producer values 68 76 }; 69 void main( Consumer & cons ) {70 cons.sum = 0;77 void main( Consumer & cons ) with( cons ) { 78 sum = 0; 71 79 for ( ;; ) { 72 80 yield( random( 5 ) ); 73 int item = remove( cons.buffer );74 if ( item == -1 ) break;// sentinel ?75 cons.sum += item;81 int item = remove( buffer ); 82 if ( item == Sentinel ) break; // sentinel ? 83 sum += item; 76 84 } // for 77 85 } 78 void ?{}( Consumer & cons, Buffer * buffer, int *sum ) {86 void ?{}( Consumer & cons, Buffer(int) * buffer, int & sum ) { 79 87 &cons.buffer = buffer; 80 &cons.sum = sum;88 &cons.sum = ∑ 81 89 } 82 90 83 91 int main() { 84 Buffer buffer;85 enum { Prods = 5, Cons = 5 };92 Buffer(int) buffer; 93 enum { Prods = 4, Cons = 5 }; 86 94 Producer * prods[Prods]; 87 95 Consumer * cons[Cons]; 88 const int Sentinel = -1;89 96 int sums[Cons]; 90 97 int i; … … 94 101 srandom( 1003 ); 95 102 96 for ( i = 0; i < Cons; i += 1 ) { // create consumers97 cons[i] = new( &buffer, &sums[i] );103 for ( i = 0; i < Cons; i += 1 ) { // create consumers 104 cons[i] = new( &buffer, sums[i] ); 98 105 } // for 99 for ( i = 0; i < Prods; i += 1 ) { // create producers100 prods[i] = new( &buffer, 100000 u);106 for ( i = 0; i < Prods; i += 1 ) { // create producers 107 prods[i] = new( &buffer, 100000 ); 101 108 } // for 102 109 103 for ( i = 0; i < Prods; i += 1 ) { // wait for producers to finish110 for ( i = 0; i < Prods; i += 1 ) { // wait for producers to finish 104 111 delete( prods[i] ); 105 112 } // for 106 for ( i = 0; i < Cons; i += 1 ) { // generate sentinal values to stop consumers113 for ( i = 0; i < Cons; i += 1 ) { // generate sentinal values to stop consumers 107 114 insert( buffer, Sentinel ); 108 115 } // for 109 116 int sum = 0; 110 for ( i = 0; i < Cons; i += 1 ) { // wait for consumers to finish117 for ( i = 0; i < Cons; i += 1 ) { // wait for consumers to finish 111 118 delete( cons[i] ); 112 119 sum += sums[i]; … … 117 124 // Local Variables: // 118 125 // tab-width: 4 // 119 // compile-command: "cfa boundedBuffer .c" //126 // compile-command: "cfa boundedBufferINT.c" // 120 127 // End: //
Note: See TracChangeset
for help on using the changeset viewer.