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

Need help with WaitForMultipleObjects

Deleted_U_Intel
Employee
558 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*8 qwDueTime
INTEGER*4 dwDueTime(2)
EQUIVALENCE (qwDueTime, dwDueTime)
LOGICAL*4 TimerLoop
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()
PRINT100, ' 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
GOTO 900
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()
GOTO 900
ENDIF
status = SetWaitableTimer (hTimer(2), liDueTime2, 0, NULL, NULL, 0)
IF (.NOT. status) THEN
PRINT 1000, ' SetWaitableTimer Timer2 failed', GetLastError()
GOTO 900
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

Message Edited by bdkempke on 03-15-2004 08:28 AM

0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
558 Views
hTimer(1) = CreateWaitableTimer (NULL, .TRUE., "WaitableTimer")
...
hTimer(2) = CreateWaitableTimer (NULL, .TRUE., "WaitableTimer")

lpTimerName

...If the string specified in the lpTimerName parameter matches the name of an existing named timer object, the call returns successfully and the GetLastError function returns ERROR_ALREADY_EXISTS.
Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
558 Views

...also, the strings used in API calls have to be C-style, i.e.char(0) terminated -- append a 'C' or //char(0). Although the code appears to work without them, it can easily failunder different conditions.

Jugoslav

0 Kudos
Reply