A function is meant to do some processing on the input and return a single value, whereas a task is more general and can calculate multiple result values and return them using output and inout type arguments. Tasks can contain simulation time consuming elements such as @, posedge and others. There are two ways in which tasks can be written, which we'll see next.
The keyword automatic will make the task reentrant, otherwise it will be static by default. If a task is static, then all its member variables will be shared across different invocations of the same task that has been launched to run concurrently. Note that auomatic task items cannot be accessed by hierarchical references.