Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29398 Discussions

Need help with WaitForMultipleObjects

Deleted_U_Intel
Employee
542 Views
I'm having a problem getting the WaitForMultipleObjects WIN32API feature to work from Intel Fortran. (It works in a C snippet I wrote, but I need it to work in the Fortran.)
What happens with this bit of code is that the 10 Second timer goes off, but the code never recognizes the 15 Second timer as having expired. If I move the 15 Second timer to the first position in the (pHandle) array, then the 15 Second timer is the only one to fire....
Here is the code I am having a problem with:
PROGRAM TimersEX
USE KERNEL32
IMPLICIT NONE
INTEGER*4 status, status2
INTEGER(PHANDLE) hTimer(2)
TYPE (T_LARGE_INTEGER) liDueTime1, liDueTime2
INTEGER*4 status, status2

INTEGER(PHANDLE) hTimer(2)

TYPE (T_LARGE_INTEGER) liDueTime1, liDueTime2

INTEGER*8 qwDueTime

INTEGER*4 dwDueTime(2)

EQUIVALENCE (qwDueTime,dwDueTime)

LOGICAL*4 TimerLoop

! Body of TimersEx

TimerLoop = .TRUE.

qwDueTime = -10 * 10000000

liDueTime1.LowPart = dwDueTime(1)

liDueTime1.HighPart = dwDueTime(2)

qwDueTime = -15 * 10000000

liDueTime2.LowPart = dwDueTime(1)

liDueTime2.HighPart = dwDueTime(2)

! create waitable timers

hTimer(1) = CreateWaitableTimer (NULL, .TRUE., "WaitableTimer")

IF (hTimer(1) .EQ. 0) THEN

status = GetLastError()

PRINT 100, ' CreateWaitableTimer (Timer1) failed', status

GOTO 900

ENDIF

hTimer(2) = CreateWaitableTimer (NULL, .TRUE., "WaitableTimer")

IF (hTimer(2) .EQ. 0) THEN

status = GetLastError()

PRINT 100, ' CreateWaitableTimer (Timer2) failed', status

TimerLoop = .TRUE.

ENDIF

! set timers to wait for 10 and 15 seconds

status = SetWaitableTimer (hTimer(1), liDueTime1, 0, NULL, NULL, 0)

IF (.NOT. status) THEN

PRINT 100, ' SetWaitableTimer Timer1 failed', GetLastError()

TimerLoop = .TRUE.

ENDIF

status = SetWaitableTimer (hTimer(2), liDueTime2, 0, NULL, NULL, 0)

IF (.NOT. status) THEN

PRINT 100, ' SetWaitableTimer Timer2 failed', GetLastError()

TimerLoop = .TRUE.

ENDIF

DO WHILE (TimerLoop .EQ. .TRUE.)

! wait for timer

status = WaitForMultipleObjects (2, %ref(hTimer), .FALSE., INFINITE)

IF (status .EQ. 0) THEN

PRINT 100, ' Timer1 was signaled', status

! reset timer for 10 seconds

status2 = SetWaitableTimer (hTimer(1), liDueTime1, 0, NULL, NULL, 0)

IF (.NOT. status2) THEN

PRINT 100, ' SetWaitableTimer Timer1 failed', GetLastError()

TimerLoop = .FALSE.

ENDIF

ELSE IF (status .EQ. 1) THEN

PRINT 100, ' Timer2 was signaled', status

! reset timer for 15 seconds

status2 = SetWaitableTimer (hTimer(2), liDueTime2, 0, NULL, NULL, 0)

IF (.NOT. status2) THEN

PRINT 100, ' SetWaitableTimer Timer2 failed', GetLastError()

TimerLoop = .FALSE.

ENDIF

ELSE

PRINT 100, ' WaitForMultipleObject failed', GetLastError()

TimerLoop = .FALSE.

ENDIF

END DO

100 FORMAT ( A, ':', X, '[', D, ']' )

900 CONTINUE

end program TimersEx

0 Kudos
0 Replies
Reply