[Migrated content. Thread originally posted on 17 February 2005]I'm just wondering if my code is a good way to handle threads.
The routines are working great, but I know one has to be carefull with threads.
PROGRAM-1 fills a grid with data after it has been sorted.
The user can click another heading of the grid wich calls the sort-routine again on other data.
It's my intention to give the user a message when the sort is taking too long (> 3 Secs).
If it's a good way of programming threads, maybe some other users can use the source as well.
Kind regards ;-)
PROGRAM-1 does the sort and fills the grid.
PERFORM FILL00 THRU FILL99.
PERFORM THREAD "TIMING" HANDLE IN TIMING-HANDLE.
* DO THE SORT AND FILL THE GRID
* END OF SORT AND FILLING GRID.
SET END-THREAD TO TRUE.
STOP THREAD TIMER-HANDLE.
STOP THREAD MESSAGE-HANDLE.
PERFORM TIMER00 THRU TIMER99.
INITIALIZE DIFF-SEC SA-SEC1 SA-SEC2 THREAD-STATUS.
ACCEPT WTIME FROM TIME.
MOVE SEC OF WTIMER TO SA-SEC1.
PERFORM UNTIL DIFF-SEC = 3
ACCEPT WTIME FROM TIME
MOVE SEC OF WTIMER TO SA-SEC2
SUBTRACT SA-SEC1 FROM SA-SEC2 GIVING DIFF-SEC
IF DIFF-SEC = 3
AND NOT END-THREAD
MOVE 1 TO READ-MESS-NR(1)
MOVE 2 TO READ-MESS-NR(2)
CALL THREAD "MESSAGE" HANDLE MESSAGE-HANDLE
MESSAGE is a separate program were messages are been displayed to the user if the grid hasn't been filled with data after 3 secs.
Maybe it would be better to make it a routine, instead of a seperate program ?
PERFORM BEGIN00 THRU BEGIN99.
RECEIVE THREAD-STATUS FROM ANY THREAD.
SET EXIT-PUSHED TO TRUE
GO TO BEGIN00