Section H3)

Implementing abort/cancel for outstanding messages (abort)

The -core v1.0 language and implementation do not support the cancellation of outstanding messages. We denote a message send by an asynchronous call with an explicit after to be outstanding, unless it has already started to execute. I.e., a released but not yet running message may be aborted/cancelled.
(Implementing abort is yet another assignment for the students in Compiler Construction at LTU, fall 2014.)

Let us first have a look at an example program using both pend and abort

// TestAbort.core
// Per Lindgren (C) 2014
//
// Example showing the use of both pend and abort
Task task_to_abort() {
	#> printf("Task to abort, not aborted\n");<#
}

Task task_print(char c) {
	#> printf("Char entered %c, Current time !!!! %f\n", c, RT_time_to_float(RT_get_bl()));<#
}

Idle {
	#> printf("User Idle\n"); <#
	m := async after 5s task_to_abort();
	#>
	char c = getc(stdin);
	<#
	abort (m);
	pend before 1s task_print(c);
}



We see that, in order to later abort a message, we need a "hook" to the message/task instance.
m := async after 5s task_to_abort();

To this end we introduce the assignment operator := and the additional syntax tin the language:

...
stmt:
  | #> C-code <#                                  
  | "async" after? before? ID ( C-params ) ;  
  | ID ":=" "async" after? before? ID ( C-params ) ;  
...

(Un-hooked async should still be possible. alternatively we could write:)
...
stmt:
  | #> C-code <#                                  
  | (ID ":=")? "async" after? before? ID ( C-params ) ;  
...


You may start by altering the Parser (add ASSIGN) and give a rule for it in the Lexer.ml.
Second thing is to add an additional field (string) to the statement constructor Async.

Similar to the halt (Section H.1) you will need to adopt a few more files in the compiler.
After that you should be able to get the above TestAbort.core to be accepted.

What about code generation?

ICGenRT.ml

Assume there is a primitive in the run-time that aborts a message (given a hook). (We will provide you with PTCORE/WINCORE doing exactly that.)

"RT_abort(" ^ par ^ ");" 


Also you may assume there is a type for the hook, given in RTFM-RT.h
RTFM_msg


The prototype for the RTFM_async is given as:
RTFM_msg RTFM_async(RTFM_time, RTFM_time, int, int);


Your assignment is now to look at the code generation for the Async statement, and adopt it such that it:
  1. defines the C-variable (given as an ID from the grammar) as a variable of type RTFM_msg
  2. sets the message parameters (look at the existing code)
  3. assigns the message hook to the result of RTFM_async

After doing this successfully, the example program should compile and run according to the semantics given for abort.

Per Lindgren, September 8th.

Last edited Sep 7, 2014 at 10:58 PM by RTFMPerLindgren, version 6