Skip to main content

[archive] Threading and Subprograms

  • October 15, 2008
  • 4 replies
  • 0 views

[Migrated content. Thread originally posted on 15 October 2008]

I'm trying to develop a progress bar subroutine. The basic concept is that the subroutine is run in a thread, wakes up every so often and displays it progress. Progress might be expressed in times or "ticks".

Anyway, the guts of this are to wake up every so often and do something on the screen. I've tried using C$SLEEP and a time out on an ACCEPT, but neither seems to accomplish the task. The subroutine is CALLed IN THREAD, which (I think) should allow it to keep running while the main program runs too. What I get when I run this and WAIT on the thread is behavior exactly as I want. What I get when I run this and continue to do work in the main program is the progress bar window with 0 progress shown, and no change over timing. This appears to indicate that the subroutine thread is never getting dispatched, perhaps because it is C$SLEEPing. That's why I tried the ACCEPT time out, but that behaves the same way. I've also tried setting the thread priority to the 32767, but no joy.

Anyone have any ideas on this? BTW, this is with AcuCOBOL 6.2.

Bill Diener

4 replies

[Migrated content. Thread originally posted on 15 October 2008]

I'm trying to develop a progress bar subroutine. The basic concept is that the subroutine is run in a thread, wakes up every so often and displays it progress. Progress might be expressed in times or "ticks".

Anyway, the guts of this are to wake up every so often and do something on the screen. I've tried using C$SLEEP and a time out on an ACCEPT, but neither seems to accomplish the task. The subroutine is CALLed IN THREAD, which (I think) should allow it to keep running while the main program runs too. What I get when I run this and WAIT on the thread is behavior exactly as I want. What I get when I run this and continue to do work in the main program is the progress bar window with 0 progress shown, and no change over timing. This appears to indicate that the subroutine thread is never getting dispatched, perhaps because it is C$SLEEPing. That's why I tried the ACCEPT time out, but that behaves the same way. I've also tried setting the thread priority to the 32767, but no joy.

Anyone have any ideas on this? BTW, this is with AcuCOBOL 6.2.

Bill Diener
If you post some sample code, it may be easier to see your problem. I've seen similar code work before, so I know it can be done.

[Migrated content. Thread originally posted on 15 October 2008]

I'm trying to develop a progress bar subroutine. The basic concept is that the subroutine is run in a thread, wakes up every so often and displays it progress. Progress might be expressed in times or "ticks".

Anyway, the guts of this are to wake up every so often and do something on the screen. I've tried using C$SLEEP and a time out on an ACCEPT, but neither seems to accomplish the task. The subroutine is CALLed IN THREAD, which (I think) should allow it to keep running while the main program runs too. What I get when I run this and WAIT on the thread is behavior exactly as I want. What I get when I run this and continue to do work in the main program is the progress bar window with 0 progress shown, and no change over timing. This appears to indicate that the subroutine thread is never getting dispatched, perhaps because it is C$SLEEPing. That's why I tried the ACCEPT time out, but that behaves the same way. I've also tried setting the thread priority to the 32767, but no joy.

Anyone have any ideas on this? BTW, this is with AcuCOBOL 6.2.

Bill Diener
Here's some of the actual code, both for the caller and the called routines.

***CALLER
PROGRESS-BAR-UP.
MOVE "T" TO COUNT-METHOD
MOVE "R" TO END-ACTION
MOVE 5 TO MAX-DURATION
MOVE .5 TO TIME-INCREMENT
CALL IN THREAD "STATUSBAR" HANDLE IN STATUS-BAR-HANDLE
USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
END-CALL
* SET THREAD STATUS-BAR-HANDLE PRIORITY TO 32767

.
PROGRESS-BAR-DOWN.
CALL "STATUSBAR-DONE" USING LK-COMMON
STATUS-BAR-OPTIONS-PTR
WAIT FOR THREAD STATUS-BAR-HANDLE
CANCEL "STATUSBAR"
DESTROY STATUS-BAR-HANDLE
.



***STATUSBAR
LINKAGE SECTION.
01 STATUS-BAR-OPTIONS.
05 COUNT-METHOD PIC X.
88 COUNT-TIME VALUE "T".
88 COUNT-TICKS VALUE "K".
05 END-ACTION PIC X.
88 EXIT-ON-END VALUE "E".
88 RESTART-ON-END VALUE "R".
88 WAIT-FOR-DONE VALUE "W".
05 MAX-DURATION PIC 9(5)V99 COMP-3.
05 TIME-INCREMENT PIC 9V99 COMP-3.
05 CUR-DURATION PIC 9(5)V99 COMP-3.

01 STATUS-BAR-OPTIONS-PTR POINTER.


SCREEN SECTION.

01 STBAR.
03 Screen1-Fr-Progress, Frame,
COL 1.80, LINE 2.20, LINES 3.30 CELLS, SIZE 18.70 CELLS,
RIMMED, FILL-COLOR 11, FILL-PERCENT 0, FILL-COLOR2 16,
FONT IS Small-Font, ID IS 3, BACKGROUND-LOW.
03 Screen1-Ef-1, Entry-Field,
COL 1.80 LINE 5.29 LINES 1.00 CELLS, SIZE 5.00 CELLS,
NO-BOX, FONT IS Small-Font, ID IS 5, NO-AUTOSEL.
03 Screen1-Pb-1, Push-Button,
COL 7.70, LINE 6.30, LINES 2.10 CELLS, SIZE 6.80 CELLS,
FONT IS Small-Font, ID IS 4,
TITLE "&Cancel".

PROCEDURE DIVISION USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR.


000-MAIN.
ACCEPT System-Information FROM System-Info
ACCEPT Terminal-Abilities FROM Terminal-Info
CALL "M$ALLOC" USING LENGTH OF STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
IF STATUS-BAR-OPTIONS-PTR = NULL
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
IF TIME-INCREMENT = ZERO
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
MOVE STATUS-BAR-OPTIONS TO WS-OPTIONS
SET ADDRESS OF STATUS-BAR-OPTIONS TO
STATUS-BAR-OPTIONS-PTR
MOVE WS-OPTIONS TO STATUS-BAR-OPTIONS
MOVE 0 TO CUR-DURATION

DISPLAY Floating GRAPHICAL WINDOW
LINES 5.60, SIZE 20.20, CELL HEIGHT 10, CELL WIDTH 10,
BIND TO THREAD, COLOR IS 65793, LABEL-OFFSET 0,
NO SCROLL,| MODELESS,
TITLE " Processing - Please Wait", TITLE-BAR,
NO WRAP,
EVENT PROCEDURE Screen1-Event-Proc
HANDLE IS STBAR-Handle
MODIFY Screen1-Fr-Progress FILL-PERCENT 0
MODIFY Screen1-Ef-1 VISIBLE FALSE
DISPLAY STBAR UPON STBAR-Handle

SET Exit-Pushed TO FALSE
PERFORM TIMER-WAIT UNTIL Exit-Pushed

DESTROY STBAR-Handle
INITIALIZE Key-Status

SET LK-IS-SUCCESS TO TRUE
EXIT PROGRAM
STOP RUN
.

TIMER-WAIT.
CALL "C$SLEEP" USING TIME-INCREMENT
IF COUNT-TIME
ADD TIME-INCREMENT TO CUR-DURATION
END-IF
COMPUTE WS-FILL-PERC ROUNDED = CUR-DURATION * 100 /
MAX-DURATION
IF WS-FILL-PERC > 100
MOVE 100 TO WS-FILL-PERC
END-IF
MODIFY SCREEN1-FR-PROGRESS FILL-PERCENT WS-FILL-PERC
IF CUR-DURATION >= MAX-DURATION
EVALUATE TRUE
WHEN EXIT-ON-END
SET EXIT-PUSHED TO TRUE
WHEN RESTART-ON-END
MOVE 0 TO CUR-DURATION
WHEN WAIT-FOR-DONE
IF TIME-INCREMENT = 0
SET EXIT-PUSHED TO TRUE
ELSE
IF COUNT-TIME
COMPUTE CUR-DURATION = MAX-DURATION -
TIME-INCREMENT
ELSE
COMPUTE CUR-DURATION = MAX-DURATION - 1
END-IF
END-IF
END-EVALUATE
END-IF
.
Screen1-Event-Proc.
.

***STATUSBAR-DONE
SET ADDRESS OF STATUS-BAR-OPTIONS TO STATUS-BAR-OPTIONS-PTR
MOVE MAX-DURATION TO CUR-DURATION
MOVE 0 TO TIME-INCREMENT
SET EXIT-ON-END TO TRUE
SET LK-IS-SUCCESS TO TRUE
GOBACK
.

[Migrated content. Thread originally posted on 15 October 2008]

I'm trying to develop a progress bar subroutine. The basic concept is that the subroutine is run in a thread, wakes up every so often and displays it progress. Progress might be expressed in times or "ticks".

Anyway, the guts of this are to wake up every so often and do something on the screen. I've tried using C$SLEEP and a time out on an ACCEPT, but neither seems to accomplish the task. The subroutine is CALLed IN THREAD, which (I think) should allow it to keep running while the main program runs too. What I get when I run this and WAIT on the thread is behavior exactly as I want. What I get when I run this and continue to do work in the main program is the progress bar window with 0 progress shown, and no change over timing. This appears to indicate that the subroutine thread is never getting dispatched, perhaps because it is C$SLEEPing. That's why I tried the ACCEPT time out, but that behaves the same way. I've also tried setting the thread priority to the 32767, but no joy.

Anyone have any ideas on this? BTW, this is with AcuCOBOL 6.2.

Bill Diener
Here's some of the actual code, both for the caller and the called routines.

***CALLER
PROGRESS-BAR-UP.
MOVE "T" TO COUNT-METHOD
MOVE "R" TO END-ACTION
MOVE 5 TO MAX-DURATION
MOVE .5 TO TIME-INCREMENT
CALL IN THREAD "STATUSBAR" HANDLE IN STATUS-BAR-HANDLE
USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
END-CALL
* SET THREAD STATUS-BAR-HANDLE PRIORITY TO 32767

.
PROGRESS-BAR-DOWN.
CALL "STATUSBAR-DONE" USING LK-COMMON
STATUS-BAR-OPTIONS-PTR
WAIT FOR THREAD STATUS-BAR-HANDLE
CANCEL "STATUSBAR"
DESTROY STATUS-BAR-HANDLE
.



***STATUSBAR
LINKAGE SECTION.
01 STATUS-BAR-OPTIONS.
05 COUNT-METHOD PIC X.
88 COUNT-TIME VALUE "T".
88 COUNT-TICKS VALUE "K".
05 END-ACTION PIC X.
88 EXIT-ON-END VALUE "E".
88 RESTART-ON-END VALUE "R".
88 WAIT-FOR-DONE VALUE "W".
05 MAX-DURATION PIC 9(5)V99 COMP-3.
05 TIME-INCREMENT PIC 9V99 COMP-3.
05 CUR-DURATION PIC 9(5)V99 COMP-3.

01 STATUS-BAR-OPTIONS-PTR POINTER.


SCREEN SECTION.

01 STBAR.
03 Screen1-Fr-Progress, Frame,
COL 1.80, LINE 2.20, LINES 3.30 CELLS, SIZE 18.70 CELLS,
RIMMED, FILL-COLOR 11, FILL-PERCENT 0, FILL-COLOR2 16,
FONT IS Small-Font, ID IS 3, BACKGROUND-LOW.
03 Screen1-Ef-1, Entry-Field,
COL 1.80 LINE 5.29 LINES 1.00 CELLS, SIZE 5.00 CELLS,
NO-BOX, FONT IS Small-Font, ID IS 5, NO-AUTOSEL.
03 Screen1-Pb-1, Push-Button,
COL 7.70, LINE 6.30, LINES 2.10 CELLS, SIZE 6.80 CELLS,
FONT IS Small-Font, ID IS 4,
TITLE "&Cancel".

PROCEDURE DIVISION USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR.


000-MAIN.
ACCEPT System-Information FROM System-Info
ACCEPT Terminal-Abilities FROM Terminal-Info
CALL "M$ALLOC" USING LENGTH OF STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
IF STATUS-BAR-OPTIONS-PTR = NULL
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
IF TIME-INCREMENT = ZERO
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
MOVE STATUS-BAR-OPTIONS TO WS-OPTIONS
SET ADDRESS OF STATUS-BAR-OPTIONS TO
STATUS-BAR-OPTIONS-PTR
MOVE WS-OPTIONS TO STATUS-BAR-OPTIONS
MOVE 0 TO CUR-DURATION

DISPLAY Floating GRAPHICAL WINDOW
LINES 5.60, SIZE 20.20, CELL HEIGHT 10, CELL WIDTH 10,
BIND TO THREAD, COLOR IS 65793, LABEL-OFFSET 0,
NO SCROLL,| MODELESS,
TITLE " Processing - Please Wait", TITLE-BAR,
NO WRAP,
EVENT PROCEDURE Screen1-Event-Proc
HANDLE IS STBAR-Handle
MODIFY Screen1-Fr-Progress FILL-PERCENT 0
MODIFY Screen1-Ef-1 VISIBLE FALSE
DISPLAY STBAR UPON STBAR-Handle

SET Exit-Pushed TO FALSE
PERFORM TIMER-WAIT UNTIL Exit-Pushed

DESTROY STBAR-Handle
INITIALIZE Key-Status

SET LK-IS-SUCCESS TO TRUE
EXIT PROGRAM
STOP RUN
.

TIMER-WAIT.
CALL "C$SLEEP" USING TIME-INCREMENT
IF COUNT-TIME
ADD TIME-INCREMENT TO CUR-DURATION
END-IF
COMPUTE WS-FILL-PERC ROUNDED = CUR-DURATION * 100 /
MAX-DURATION
IF WS-FILL-PERC > 100
MOVE 100 TO WS-FILL-PERC
END-IF
MODIFY SCREEN1-FR-PROGRESS FILL-PERCENT WS-FILL-PERC
IF CUR-DURATION >= MAX-DURATION
EVALUATE TRUE
WHEN EXIT-ON-END
SET EXIT-PUSHED TO TRUE
WHEN RESTART-ON-END
MOVE 0 TO CUR-DURATION
WHEN WAIT-FOR-DONE
IF TIME-INCREMENT = 0
SET EXIT-PUSHED TO TRUE
ELSE
IF COUNT-TIME
COMPUTE CUR-DURATION = MAX-DURATION -
TIME-INCREMENT
ELSE
COMPUTE CUR-DURATION = MAX-DURATION - 1
END-IF
END-IF
END-EVALUATE
END-IF
.
Screen1-Event-Proc.
.

***STATUSBAR-DONE
SET ADDRESS OF STATUS-BAR-OPTIONS TO STATUS-BAR-OPTIONS-PTR
MOVE MAX-DURATION TO CUR-DURATION
MOVE 0 TO TIME-INCREMENT
SET EXIT-ON-END TO TRUE
SET LK-IS-SUCCESS TO TRUE
GOBACK
.

[Migrated content. Thread originally posted on 15 October 2008]

I'm trying to develop a progress bar subroutine. The basic concept is that the subroutine is run in a thread, wakes up every so often and displays it progress. Progress might be expressed in times or "ticks".

Anyway, the guts of this are to wake up every so often and do something on the screen. I've tried using C$SLEEP and a time out on an ACCEPT, but neither seems to accomplish the task. The subroutine is CALLed IN THREAD, which (I think) should allow it to keep running while the main program runs too. What I get when I run this and WAIT on the thread is behavior exactly as I want. What I get when I run this and continue to do work in the main program is the progress bar window with 0 progress shown, and no change over timing. This appears to indicate that the subroutine thread is never getting dispatched, perhaps because it is C$SLEEPing. That's why I tried the ACCEPT time out, but that behaves the same way. I've also tried setting the thread priority to the 32767, but no joy.

Anyone have any ideas on this? BTW, this is with AcuCOBOL 6.2.

Bill Diener
Here's some of the actual code, both for the caller and the called routines.

***CALLER
PROGRESS-BAR-UP.
MOVE "T" TO COUNT-METHOD
MOVE "R" TO END-ACTION
MOVE 5 TO MAX-DURATION
MOVE .5 TO TIME-INCREMENT
CALL IN THREAD "STATUSBAR" HANDLE IN STATUS-BAR-HANDLE
USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
END-CALL
* SET THREAD STATUS-BAR-HANDLE PRIORITY TO 32767

.
PROGRESS-BAR-DOWN.
CALL "STATUSBAR-DONE" USING LK-COMMON
STATUS-BAR-OPTIONS-PTR
WAIT FOR THREAD STATUS-BAR-HANDLE
CANCEL "STATUSBAR"
DESTROY STATUS-BAR-HANDLE
.



***STATUSBAR
LINKAGE SECTION.
01 STATUS-BAR-OPTIONS.
05 COUNT-METHOD PIC X.
88 COUNT-TIME VALUE "T".
88 COUNT-TICKS VALUE "K".
05 END-ACTION PIC X.
88 EXIT-ON-END VALUE "E".
88 RESTART-ON-END VALUE "R".
88 WAIT-FOR-DONE VALUE "W".
05 MAX-DURATION PIC 9(5)V99 COMP-3.
05 TIME-INCREMENT PIC 9V99 COMP-3.
05 CUR-DURATION PIC 9(5)V99 COMP-3.

01 STATUS-BAR-OPTIONS-PTR POINTER.


SCREEN SECTION.

01 STBAR.
03 Screen1-Fr-Progress, Frame,
COL 1.80, LINE 2.20, LINES 3.30 CELLS, SIZE 18.70 CELLS,
RIMMED, FILL-COLOR 11, FILL-PERCENT 0, FILL-COLOR2 16,
FONT IS Small-Font, ID IS 3, BACKGROUND-LOW.
03 Screen1-Ef-1, Entry-Field,
COL 1.80 LINE 5.29 LINES 1.00 CELLS, SIZE 5.00 CELLS,
NO-BOX, FONT IS Small-Font, ID IS 5, NO-AUTOSEL.
03 Screen1-Pb-1, Push-Button,
COL 7.70, LINE 6.30, LINES 2.10 CELLS, SIZE 6.80 CELLS,
FONT IS Small-Font, ID IS 4,
TITLE "&Cancel".

PROCEDURE DIVISION USING LK-COMMON
STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR.


000-MAIN.
ACCEPT System-Information FROM System-Info
ACCEPT Terminal-Abilities FROM Terminal-Info
CALL "M$ALLOC" USING LENGTH OF STATUS-BAR-OPTIONS
STATUS-BAR-OPTIONS-PTR
IF STATUS-BAR-OPTIONS-PTR = NULL
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
IF TIME-INCREMENT = ZERO
SET LK-IS-UNSUCCESSFUL TO TRUE
SET LK-ERR-IS-ERROR TO TRUE
GOBACK
END-IF
MOVE STATUS-BAR-OPTIONS TO WS-OPTIONS
SET ADDRESS OF STATUS-BAR-OPTIONS TO
STATUS-BAR-OPTIONS-PTR
MOVE WS-OPTIONS TO STATUS-BAR-OPTIONS
MOVE 0 TO CUR-DURATION

DISPLAY Floating GRAPHICAL WINDOW
LINES 5.60, SIZE 20.20, CELL HEIGHT 10, CELL WIDTH 10,
BIND TO THREAD, COLOR IS 65793, LABEL-OFFSET 0,
NO SCROLL,| MODELESS,
TITLE " Processing - Please Wait", TITLE-BAR,
NO WRAP,
EVENT PROCEDURE Screen1-Event-Proc
HANDLE IS STBAR-Handle
MODIFY Screen1-Fr-Progress FILL-PERCENT 0
MODIFY Screen1-Ef-1 VISIBLE FALSE
DISPLAY STBAR UPON STBAR-Handle

SET Exit-Pushed TO FALSE
PERFORM TIMER-WAIT UNTIL Exit-Pushed

DESTROY STBAR-Handle
INITIALIZE Key-Status

SET LK-IS-SUCCESS TO TRUE
EXIT PROGRAM
STOP RUN
.

TIMER-WAIT.
CALL "C$SLEEP" USING TIME-INCREMENT
IF COUNT-TIME
ADD TIME-INCREMENT TO CUR-DURATION
END-IF
COMPUTE WS-FILL-PERC ROUNDED = CUR-DURATION * 100 /
MAX-DURATION
IF WS-FILL-PERC > 100
MOVE 100 TO WS-FILL-PERC
END-IF
MODIFY SCREEN1-FR-PROGRESS FILL-PERCENT WS-FILL-PERC
IF CUR-DURATION >= MAX-DURATION
EVALUATE TRUE
WHEN EXIT-ON-END
SET EXIT-PUSHED TO TRUE
WHEN RESTART-ON-END
MOVE 0 TO CUR-DURATION
WHEN WAIT-FOR-DONE
IF TIME-INCREMENT = 0
SET EXIT-PUSHED TO TRUE
ELSE
IF COUNT-TIME
COMPUTE CUR-DURATION = MAX-DURATION -
TIME-INCREMENT
ELSE
COMPUTE CUR-DURATION = MAX-DURATION - 1
END-IF
END-IF
END-EVALUATE
END-IF
.
Screen1-Event-Proc.
.

***STATUSBAR-DONE
SET ADDRESS OF STATUS-BAR-OPTIONS TO STATUS-BAR-OPTIONS-PTR
MOVE MAX-DURATION TO CUR-DURATION
MOVE 0 TO TIME-INCREMENT
SET EXIT-ON-END TO TRUE
SET LK-IS-SUCCESS TO TRUE
GOBACK
.