ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since b91bfde was             ecfd758, checked in by Andrew Beach <ajbeach@…>, 5 years ago           | 
        
        
          | 
             
Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            976 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | // Try cancelling a thread.
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <thread.hfa>
 | 
|---|
| 4 | #include <exception.hfa>
 | 
|---|
| 5 | 
 | 
|---|
| 6 | EHM_EXCEPTION(internal_error)();
 | 
|---|
| 7 | EHM_VIRTUAL_TABLE(internal_error, internal_vt);
 | 
|---|
| 8 | 
 | 
|---|
| 9 | thread WillCancel {};
 | 
|---|
| 10 | 
 | 
|---|
| 11 | const char * msg(ThreadCancelled(WillCancel) * this) {
 | 
|---|
| 12 |         return "ThreadCancelled(WillCancel)";
 | 
|---|
| 13 | }
 | 
|---|
| 14 | 
 | 
|---|
| 15 | void main(WillCancel &) {
 | 
|---|
| 16 |         printf("1");
 | 
|---|
| 17 |         cancel_stack((internal_error){&internal_vt});
 | 
|---|
| 18 |         printf("!");
 | 
|---|
| 19 | }
 | 
|---|
| 20 | 
 | 
|---|
| 21 | void explicit() {
 | 
|---|
| 22 |         try {
 | 
|---|
| 23 |                 printf("0");
 | 
|---|
| 24 |                 WillCancel cancel;
 | 
|---|
| 25 |                 printf("1");
 | 
|---|
| 26 |                 join(cancel);
 | 
|---|
| 27 |                 printf("4");
 | 
|---|
| 28 |         } catchResume (SomeThreadCancelled * error) {
 | 
|---|
| 29 |                 printf("2");
 | 
|---|
| 30 |                 if ((virtual internal_error *)error->the_exception) {
 | 
|---|
| 31 |                         printf("3");
 | 
|---|
| 32 |                 }
 | 
|---|
| 33 |         }
 | 
|---|
| 34 |         printf("5\n");
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | void implicit() {
 | 
|---|
| 38 |         try {
 | 
|---|
| 39 |                 {
 | 
|---|
| 40 |                         printf("0");
 | 
|---|
| 41 |                         WillCancel cancel;
 | 
|---|
| 42 |                         printf("1");
 | 
|---|
| 43 |                 }
 | 
|---|
| 44 |                 printf("4");
 | 
|---|
| 45 |         } catchResume (SomeThreadCancelled * error) {
 | 
|---|
| 46 |                 printf("2");
 | 
|---|
| 47 |                 if ((virtual internal_error *)error->the_exception) {
 | 
|---|
| 48 |                         printf("3");
 | 
|---|
| 49 |                 }
 | 
|---|
| 50 |         }
 | 
|---|
| 51 |         printf("5\n");
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | int main(int argc, char * argv[]) {
 | 
|---|
| 55 |         explicit();
 | 
|---|
| 56 |         implicit();
 | 
|---|
| 57 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.