PDA

View Full Version : How do I start a thread in Fortran.NET program?


R. T. (Fortran Man)
02-15-2005, 12:14 AM
How do I start a thread in Fortran.NET program?

Lahey Support
02-15-2005, 12:17 AM
The following example shows the syntax required to start a thread.

MODULE UserApp
USE System
USE System.Threading
TYPE, public :: TCTLTHD
CONTAINS
PROCEDURE,PASS :: AppMain ! NOPASS cannot be specified.
END TYPE TCTLTHD

CONTAINS
INTEGER(4) FUNCTION AppMain(this) ! Add arg. this.
TYPE(TCTLTHD) :: this ! Add this statement.
print *,"TEST OK"
AppMain = 12345 ! User cannot get this result.
! AppMain should be SUBROUTINE.
END FUNCTION

END MODULE UserApp

PROGRAM MAIN
USE UserApp
IMPLICIT NONE
TYPE(ThreadStart),POINTER :: AppStart
TYPE(TCTLTHD) :: th
TYPE(Thread),POINTER :: thptr

ALLOCATE(AppStart,source=ThreadStart(th.AppMain))
ALLOCATE(thptr, source=Thread(AppStart))
CALL thptr%Start() ! Start a thread.
CALL thptr%Join() ! Wait for the thread termination.

END PROGRAM