Changeset 135a2d8
- Timestamp:
- Nov 8, 2024, 5:12:48 PM (2 weeks ago)
- Branches:
- master
- Children:
- 62595b31
- Parents:
- 83a581a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/uC++toCFA/uC++toCFA.tex
r83a581a r135a2d8 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Tue Oct 22 17:45:48202414 %% Update Count : 6 06813 %% Last Modified On : Fri Nov 8 08:22:25 2024 14 %% Update Count : 6107 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 394 394 struct S { 395 395 int i, j; 396 S( int i, int j ) { S::i = i; S::j = j; }397 ~S() {}396 @S@( int i, int j ) { S::i = i; S::j = j; } 397 @~S@() {} 398 398 }; 399 399 S s = { 1, 2 }, s2{ 1, 2 }; … … 407 407 int i, j; 408 408 }; 409 void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; }410 void ^?{}( S & s) {}409 void @?{}( S & s@, int i, int j ) { s.[i, j] = [i, j]; } 410 void @^?{}( S & s@ ) {} 411 411 S s = { 1, 2 }, s2{ 1, 2 }; 412 412 S * s3 = &(*malloc()){ 1, 2 }; … … 504 504 \begin{uC++} 505 505 506 _CoroutineC {506 @_Coroutine@ C { 507 507 // private coroutine fields 508 508 void main() { 509 ... suspend();...510 ... _Resume E( ... ) _At partner;511 ... uThisCoroutine();...509 ... @suspend();@ ... 510 ... @_Resume E( ... ) _At partner;@ 511 ... @uThisCoroutine();@ ... 512 512 513 513 } 514 514 public: 515 515 void mem( ... ) { 516 ... resume()...516 ... @resume();@ ... 517 517 } 518 518 }; … … 521 521 \begin{cfa} 522 522 #include <$coroutine$.hfa> 523 coroutineC {523 @coroutine@ C { 524 524 // private coroutine fields 525 525 526 526 }; 527 527 void main( C & c ) { 528 ... suspend;... // keyword not routine529 ... resumeAt( partner, ExceptionInst( E, ... ) );530 ... active_coroutine();...528 ... @suspend;@ ... // keyword not routine 529 ... @resumeAt( partner, ExceptionInst( E, ... ) );@ 530 ... @active_coroutine();@ ... 531 531 } 532 532 void mem( C & c, ... ) { 533 ... resume( c );...533 ... @resume( c );@ ... 534 534 } 535 535 \end{cfa} … … 548 548 #include <uCobegin.h> 549 549 int main() { 550 COBEGIN550 @COBEGIN@ 551 551 BEGIN osacquire( cout ) << "A" << endl; END 552 552 BEGIN osacquire( cout ) << "B" << endl; END … … 554 554 BEGIN osacquire( cout ) << "D" << endl; END 555 555 BEGIN osacquire( cout ) << "E" << endl; END 556 COEND557 COFOR( i, 1, 10,556 @COEND@ 557 @COFOR@( i, 1, 10, 558 558 osacquire( cout ) << i << endl; 559 559 ) … … 566 566 int main() { 567 567 { 568 corun{ mutex( sout ) sout | "A"; }568 @corun@ { mutex( sout ) sout | "A"; } 569 569 corun { mutex( sout ) sout | "B"; } 570 570 corun { mutex( sout ) sout | "C"; } … … 572 572 corun { mutex( sout ) sout | "E"; } 573 573 } 574 cofor( i; 10 ) {574 @cofor@( i; 10 ) { 575 575 mutex( sout ) sout | i; 576 576 } … … 712 712 \section{Monitors} 713 713 714 Internal Scheduling 714 715 \begin{cquote} 715 716 \begin{tabular}{@{}l|ll@{}} 716 717 \begin{uC++} 717 718 718 @_Monitor@ M { 719 @uCondition@ c; 720 bool avail = true; 719 @_Monitor@ BoundedBufferI { 720 @uCondition@ full, empty; 721 int front = 0, back = 0, count = 0; 722 int elements[20]; 721 723 public: 722 724 723 void rtn() { 724 if ( ! avail ) c.wait(); 725 else avail = false; 725 726 727 @_Nomutex@ int query() const { return count; } 728 729 void insert( int elem ) { 730 if ( count == 20 ) @empty.wait();@ 731 elements[back] = elem; 732 back = ( back + 1 ) % 20; 733 count += 1; 734 @full.signal();@ 735 } 736 int remove() { 737 if ( count == 0 ) @full.wait();@ 738 int elem = elements[front]; 739 front = ( front + 1 ) % 20; 740 count -= 1; 741 @empty.signal();@ 742 return elem; 726 743 } 727 744 }; … … 730 747 \begin{cfa} 731 748 #include <$monitor$.hfa> 732 @monitor@ M { 733 @condition@ c; 734 bool avail; 735 }; 736 void ?{}( M & m ) { m.avail = true; } 737 void rtn( M & m ) with( m ) { 738 if ( ! avail ) wait( c ); 739 else avail = false; 740 } 741 742 \end{cfa} 743 \\ 744 \multicolumn{2}{@{}l@{}}{\lstinline{M m;}} 749 @monitor@ BoundedBufferI { 750 @condition@ full, empty; 751 int front, back, count; 752 int elements[20]; 753 }; 754 void ?{}( BoundedBufferI & buf ) with( buf ) { 755 front = back = count = 0; 756 } 757 int query( BoundedBufferI & buf ) { return buf.count; } 758 int remove( BoundedBufferI & @mutex@ buf ); // forward 759 void insert( BoundedBufferI & @mutex@ buf, int elem ) with( buf ) { 760 if ( count == 20 ) @wait( empty );@ 761 elements[back] = elem; 762 back = ( back + 1 ) % 20; 763 count += 1 764 @signal( full );@ 765 } 766 int remove( BoundedBufferI & @mutex@ buf ) with( buf ) { 767 if ( count == 0 ) @wait( full );@ 768 int elem = elements[front]; 769 front = ( front + 1 ) % 20; 770 count -= 1; 771 @signal( empty );@ 772 return elem; 773 } 774 775 \end{cfa} 776 \end{tabular} 777 \end{cquote} 778 \enlargethispage{1000pt} 779 External Scheduling 780 \begin{cquote} 781 \begin{tabular}{@{}l|ll@{}} 782 \begin{uC++} 783 784 _Monitor BoundedBuffer { 785 int front = 0, back = 0, count = 0; 786 int elements[20]; 787 public: 788 _Nomutex int query() const { return count; } 789 void insert( int elem ); 790 int remove(); 791 }; 792 793 void BoundedBuffer::insert( int elem ) { 794 if ( count == 20 ) @_Accept( remove );@ 795 elements[back] = elem; 796 back = ( back + 1 ) % 20; 797 count += 1; 798 } 799 int BoundedBuffer::remove() { 800 if ( count == 0 ) @_Accept( insert );@ 801 int elem = elements[front]; 802 front = ( front + 1 ) % 20; 803 count -= 1; 804 return elem; 805 } 806 \end{uC++} 807 & 808 \begin{cfa} 809 #include <$monitor$.hfa> 810 monitor BoundedBuffer { 811 int front, back, count; 812 int elements[20]; 813 }; 814 void ?{}( BoundedBuffer & buf ) with( buf ) { 815 front = back = count = 0; 816 } 817 int query( BoundedBuffer & buf ) { return buf.count; } 818 int remove( BoundedBuffer & @mutex@ buf ); // forward 819 void insert( BoundedBuffer & @mutex@ buf, int elem ) with( buf ) { 820 if ( count == 20 ) @waitfor( remove : buf );@ 821 elements[back] = elem; 822 back = ( back + 1 ) % 20; 823 count += 1; 824 } 825 int remove( BoundedBuffer & @mutex@ buf ) with( buf ) { 826 if ( count == 0 ) @waitfor( insert : buf );@ 827 int elem = elements[front]; 828 front = ( front + 1 ) % 20; 829 count -= 1; 830 return elem; 831 } 832 \end{cfa} 745 833 \end{tabular} 746 834 \end{cquote}
Note: See TracChangeset
for help on using the changeset viewer.