Highlighted
Absent Member.
Absent Member.
864 views

[archive] Message passing in threads

[Migrated content. Thread originally posted on 08 January 2010]

We are developing an application that allows a user to open a second screen form our main screen that will display a website. The second screen is started in a Thread and is set to independent, Modeless, Link To Thread with a Browser showing the address selected. The second screen then goes into a Perform loop accepting messages from any thread. Below is the code in the second screen that we are attempting to use (ws-new-address is being passed with messages from the 1st screen with the new address to show).



PERFORM WITH TEST AFTER UNTIL WS-X = "X"
ACCEPT PCR-VIEWER-SCREEN ALLOWING MESSAGES FROM ANY THREAD
IF KEY-STATUS = 95
RECEIVE WS-NEW-ADDRESS FROM ANY THREAD
IF WS-NEW-ADDRESS(1:12) = "close me now"
MOVE "X" TO WS-X
ELSE
MODIFY WB-1 VALUE = WS-NEW-ADDRESS
MODIFY EF-ADDRESS VALUE = WS-NEW-ADDRESS
END-IF
INITIALIZE KEY-STATUS
END-IF
END-PERFORM.
MOVE "SCREEN CLOSED" TO PASSED-ADDRESS.
SET EXIT-PUSHED TO TRUE.
DESTROY PCR-VIEWER-Handle.
INITIALIZE Key-Status.
Exit Program.



The issue that we are having is passing information back and forth in the thread. We allow the user to select a different address and that is passed using Messages to the second screen to display the new address. Code below shows the logic we are using to SEND the new address:



SEND WS-NEW-ADDRESS TO THREAD IE-THREAD
WAIT FOR IE-THREAD



We continue to try options but seem to get a "DEADLOCK in message system" error at every turn. This usually happens when we try to pass a new address to the second screen. The first display of the screen with the original address works fine.

Thanks for any help...WE NEED ALL WE CAN GET!!!!!!
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Message passing in threads

The devil is usually in the details. Without a full reproducing example, there is not much to say.

Here is an example that works.
MASTER.CBL

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  MASTER.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
       WORKING-STORAGE SECTION.
       77  CNTL-FONT                USAGE HANDLE OF FONT SMALL-FONT.
       77  hThread                  USAGE HANDLE OF THREAD.
       77  KEY-STATUS               IS SPECIAL-NAMES
           CRT STATUS               PIC 9(4) VALUE 0.
           88  CLOSE-PRESSED        VALUE 76.
           88  EXIT-PRESSED         VALUE 27.
       SCREEN      SECTION.
       01  TEMPLATE-SCREEN.
           03      PUSH-BUTTON
                   LINE             13
                   COL              23
                   SIZE             14
                   TITLE            "Close"
                   SELF-ACT
                   EXCEPTION-VALUE  = 27.
           03      PUSH-BUTTON
                   LINE             13
                   COL              63
                   SIZE             14
                   TITLE            "E&xit"
                   SELF-ACT
                   EXCEPTION-VALUE  = 27.
       PROCEDURE DIVISION.
       MAIN-LOGIC.
           DISPLAY STANDARD         GRAPHICAL WINDOW
                   TITLE            "Master"
                   CONTROL          FONT CNTL-FONT
                   SIZE             80
                   LINES            15
                   BACKGROUND-LOW.
    INITIALIZE               KEY-STATUS
           CALL    IN THREAD        "Child" HANDLE IN hThread
           DISPLAY TEMPLATE-SCREEN.
           PERFORM WITH TEST AFTER  UNTIL EXIT-PRESSED
                   ACCEPT           TEMPLATE-SCREEN
                   IF               CLOSE-PRESSED
                                    SEND "CLOSE" TO THREAD hThread
                                    SET EXIT-PRESSED TO TRUE
                   END-IF
           END-PERFORM.
           DESTROY TEMPLATE-SCREEN.
           STOP    RUN.

CHILD.CBL

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  CHILD.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
       WORKING-STORAGE SECTION.
       77  CNTL-FONT                USAGE HANDLE OF FONT SMALL-FONT.
       77  WS-STRING                PIC X(20).
       77  hWindow                  HANDLE OF WINDOW.
       77  KEY-STATUS               IS SPECIAL-NAMES
           CRT STATUS               PIC 9(4) VALUE 0.
           88  EXIT-PRESSED         VALUE 27.
           88  MSG-RECEIVED         VALUE 95.
       SCREEN      SECTION.
       01  TEMPLATE-SCREEN.
           03      PUSH-BUTTON
                   LINE             13
                   COL              63
                   SIZE             14
                   TITLE            "E&xit"
                   SELF-ACT
                   EXCEPTION-VALUE  = 27.
       PROCEDURE DIVISION.
       MAIN-LOGIC.
           DISPLAY INDEPENDENT      WINDOW
                   TITLE            "Child"
                   CONTROL          FONT CNTL-FONT
                   SIZE             80
                   LINES            15
                   BACKGROUND-LOW
                   BIND TO THREAD
                   HANDLE           IN hWindow.
           INITIALIZE               KEY-STATUS.
           DISPLAY TEMPLATE-SCREEN.
           PERFORM WITH TEST AFTER  UNTIL EXIT-PRESSED
                   ACCEPT           TEMPLATE-SCREEN ALLOWING MESSAGES
                                    FROM ANY THREAD
                   IF               MSG-RECEIVED
                                    RECEIVE WS-STRING FROM ANY THREAD
                                    IF WS-STRING = "CLOSE"
                                        SET EXIT-PRESSED TO TRUE
                                    END-IF
                   END-IF
           END-PERFORM.
           DESTROY TEMPLATE-SCREEN.
           DESTROY hWindow.
           DISPLAY MESSAGE          BOX "Leaving child thread"
           GOBACK.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Message passing in threads

I hate to bring up an old topic, but I am also trying to do this. The difference is I am using Acubench to develop my application. And I cann't for the life of me figure out where to insert my Recieve message code, as all that code is generated by acubench and it doesn't appear to add a procedure that it will call for when key-status = 95 (Message-Received).

The main loop just looks like this:


* MAIN
Acu-MAIN-Proc.
   PERFORM UNTIL Exit-Pushed
        ACCEPT MAIN ALLOWING MESSAGES FROM Any Thread
            ON EXCEPTION PERFORM Acu-MAIN-Evaluate-Func
        END-ACCEPT
    END-PERFORM
    DESTROY MAIN-HANDLE
    INITIALIZE Key-Status
    .

* MAIN
Acu-MAIN-Evaluate-Func.
     EVALUATE TRUE
        WHEN Exit-Pushed
           PERFORM Acu-MAIN-Exit
        WHEN Event-Occurred
           IF Event-Type = Cmd-Close
              PERFORM Acu-MAIN-Exit
           END-IF
     END-EVALUATE
     MOVE 1 TO Accept-Control
     .

How do I get acubench to insert the following in the above evaluate?

WHEN Message-Recieved
    PERFORM [I]my message paragraph[/I]
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Message passing in threads

Interestingly enough I think I figured out a solution. It seems like a wacky way to do it but it works. If I add a MENU DESIGNER control to the form I can add a menu item and can link it to exception 95 add the link to procedure and I'm away.

I just happend to notice that the MENU's add WHEN exception PERFORM Link-To's in the the Acu-MAIN-Evaluate-Func Procedure.

So this seems to be a workaround, But I would have thought it would have been something that would be smarter than this. Something like an actual event for you to use on the screen when you flag it to allow messages...
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Message passing in threads

Don't know what your screens looks like, but we trap the message received in an exception other block.
For example create an exception other on your main screen

       NORMAL-EX-OTHER-TRAP.
           IF Message-Received
           END-IF
           .
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.