Thread Routine Format

A function or subroutine that runs in a separate thread from the main program can take an argument. The code below shows a skeleton for a function and a subroutine:

  INTEGER(4) FUNCTION thrdfnc(arg)
     USE DFMT
     integer(4) arg
!DEC$ ATTRIBUTES VALUE :: arg
     arg = arg + 1      ! Sample only; real work goes here.
     thrdfnc = 0        ! Sets exit code to 0.
  END FUNCTION

  SUBROUTINE thrdfnc2 (arg2)
     USE DFMT
     integer(4) arg2
!DEC$ ATTRIBUTES VALUE :: arg2
           ! Subroutine work goes here.
     Call exitthread(0) ! Exit code is 0.
  END SUBROUTINE

The arguments arg or arg2 are passed to the function or subroutine when the main program calls CreateThread, as the fourth argument. The arguments arg or arg2 are passed by value.

Threads automatically terminate when the function or subroutine terminates.