Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

CreateThread in Fortran

Tote_Licences
Beginner
984 Views
I'm trying to use the CreateThread call in Fortran (Visual Fortran Composer XE 2011).

I supply a procedure name and a parameter to be used:-

THandle = CREATETHREAD (0, 0 ,sched_ServerThread ,IntegerParameter ,0 ,ThreadID)

Once the thread has started, the "sched_serverThread" subroutine is executed
SUBROUTINE
sched_ServerThread(SystemNum)

In this subroutine, the supplied parameter (SystemNum defined as Integer*4) has an"undefined address", thus causing a few poblems in the subsequent code.
I presume I am doing something obviously incorrect?

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
984 Views
Try

INTERFACE
INTEGER(HANDLE) FUNCTION sched_ServerThread(SystemNum)
!DEC$ ATTRIBUTES STDCALL, ALIAS:"_systemnum" :: SystemNum
INTEGER(4), POINTER :: SystemNum
END FUNCTION sched_ServerThread
END INTERFACE


And have the above interface visible to both the caller and the callee

You had two basic problems:

You did not declare STDCALL calling conventions
You use subroutine when function was required

You may be able to eliminate POINTER on SystemNum. I had it in there for use back in V8.nn when the supplied interface declarations of the Windows API was in error.

Jim Dempsey
0 Kudos
Tote_Licences
Beginner
984 Views

Hi Jim,
Thanks for the attempt, but I seem to have a few problems implementing your solution.
I did change the subroutine to Integer function, thentried to compile with the supplied interface. The compiler finds that the SystemNum variable isfound to have been defined more than once with conflicting attributes. Commenting out the Pointer defintion had no effect.
It seems to me that the stdcall attribute would be used to interface to a C routine (which this is not) and that therefore the Alias clause should refer to the C alias to the fortran function (the C routine does not exist).
With that in mind I changed the Interface defintion to exclude the atttributes stdcall defintion. It then compiled OK, but failed to have any affect on the original problem.
Graham

0 Kudos
jimdempseyatthecove
Honored Contributor III
984 Views
Graham,

CreateThread is a C runtime system function:
HANDLE CreateThread(
  LPSECURITY_ATTRIBUTES lpThreadAttributes,
  SIZE_T dwStackSize,
  LPTHREAD_START_ROUTINE lpStartAddress,
  LPVOID lpParameter,
  DWORD dwCreationFlags,
  LPDWORD lpThreadId
);
You can also call _beginthread _endthread
Jim Dempsey

0 Kudos
Reply