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 b3a0df6 was             ab8c6a6, checked in by Andrew Beach <ajbeach@…>, 5 years ago           | 
        
        
          | 
             
Thread Cancellation, a test for it and a required fix to Specialization. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            934 bytes
           | 
        
      
      
| Rev | Line |   | 
|---|
| [ab8c6a6] | 1 | // Try cancelling a thread.
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | #include <thread.hfa>
 | 
|---|
 | 4 | #include <exception.hfa>
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | TRIVIAL_EXCEPTION(internal_error);
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | thread WillCancel {};
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | const char * msg(ThreadCancelled(WillCancel) * this) {
 | 
|---|
 | 11 |         return "ThreadCancelled(WillCancel)";
 | 
|---|
 | 12 | }
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | void main(WillCancel &) {
 | 
|---|
 | 15 |         printf("1");
 | 
|---|
 | 16 |         cancel_stack((internal_error){});
 | 
|---|
 | 17 |         printf("!");
 | 
|---|
 | 18 | }
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | void explicit() {
 | 
|---|
 | 21 |         try {
 | 
|---|
 | 22 |                 printf("0");
 | 
|---|
 | 23 |                 WillCancel cancel;
 | 
|---|
 | 24 |                 printf("1");
 | 
|---|
 | 25 |                 join(cancel);
 | 
|---|
 | 26 |                 printf("4");
 | 
|---|
 | 27 |         } catchResume (ThreadCancelled(WillCancel) * error) {
 | 
|---|
 | 28 |                 printf("2");
 | 
|---|
 | 29 |                 if ((virtual internal_error *)error->the_exception) {
 | 
|---|
 | 30 |                         printf("3");
 | 
|---|
 | 31 |                 }
 | 
|---|
 | 32 |         }
 | 
|---|
 | 33 |         printf("5\n");
 | 
|---|
 | 34 | }
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | void implicit() {
 | 
|---|
 | 37 |         try {
 | 
|---|
 | 38 |                 {
 | 
|---|
 | 39 |                         printf("0");
 | 
|---|
 | 40 |                         WillCancel cancel;
 | 
|---|
 | 41 |                         printf("1");
 | 
|---|
 | 42 |                 }
 | 
|---|
 | 43 |                 printf("4");
 | 
|---|
 | 44 |         } catchResume (ThreadCancelled(WillCancel) * error) {
 | 
|---|
 | 45 |                 printf("2");
 | 
|---|
 | 46 |                 if ((virtual internal_error *)error->the_exception) {
 | 
|---|
 | 47 |                         printf("3");
 | 
|---|
 | 48 |                 }
 | 
|---|
 | 49 |         }
 | 
|---|
 | 50 |         printf("5\n");
 | 
|---|
 | 51 | }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | int main(int argc, char * argv[]) {
 | 
|---|
 | 54 |         explicit();
 | 
|---|
 | 55 |         implicit();
 | 
|---|
 | 56 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.