Highlighted
Absent Member.
Absent Member.
372 views

[archive] Some help with Threads please.

[Migrated content. Thread originally posted on 28 November 2007]

I want to have a diary whitin my program using a thread.
I first open the files and then wait to make sure all files are open.

Then I call a thread which reads a file and displays a message (when neccessary).
However whithin this thread the files are NOT open.

Can someone help me whith this problem.


PERFORM THREAD OPEN-FILES HANDLE IN THREAD-1.
WAIT FOR THREAD-1.
PERFORM THREAD TEST-REMARK UNTIL EOJ.

* TEST IF THERE'S A REMARK
TEST-REMARK SECTION.
BEGIN.
MOVE 01 TO RECORD-NO.
READ PROFILE RECORD.

ENDS.
EXIT.
* ---------- OPEN FILES ------------*
OPEN-FILES SECTION.
BEGIN.
OPEN INPUT PROFILE.
ENDS.
EXIT.
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Some help with Threads please.

I want to have a diary whitin my program using a thread.


PERFORM THREAD OPEN-FILES HANDLE IN THREAD-1.
WAIT FOR THREAD-1.
PERFORM THREAD TEST-REMARK UNTIL EOJ.

* TEST IF THERE'S A REMARK
TEST-REMARK SECTION.
BEGIN.
MOVE 01 TO RECORD-NO.
READ PROFILE RECORD.

ENDS.
EXIT.
* ---------- OPEN FILES ------------*
OPEN-FILES SECTION.
BEGIN.
OPEN INPUT PROFILE.
ENDS.
EXIT.


hi,
I think it' a problem of syncronization:
wait statement terminates when thread-1 terminates or send message, maybe your opening files thread sends message and then TEST-REMARK thread starts before other is finished. Personally I prefer implement a structure like:
...
78 k-my-timeout value 500.
78 k-t-start value "S".
78 k-t-pause value "P".
78 k-t-terminate value "T".
77 w-t-input1 pic x(01).
77 w-t-output1 pic x(01).
77 w-t-input2 pic x(01).
77 w-t-output2 pic x(01).
...

|start thread1
perform thread thread1 ,
handle in w-t-handle1
|tells thread1 to execute
send k-t-start to thread w-t-handle1
|waits for thread1 to answer in appropriate manner
perform test after until (w-t-output1 = k-t-start)
receive w-t-output1 from thread w-t-handle1
end-perform
|thread1 is started let's start thread2
perform thread thread2 ,
handle in w-t-handle2
send k-t-start to thread w-t-handle2
perform test after until (w-t-output2 <> k-t-start)
receive w-t-output2 from thread w-t-handle2
end-perform
perform test after until (w-t-output1 = k-t-terminate)
and (w-t-output2 = k-t-terminate)
receive w-t-output1 from thread w-t-handle1
before time k-my-timeout
receive w-t-output2 from thread w-t-handle2
before time k-my-timeout
end-perform

...
thread1.
|wait for explicit start
perform test after until (w-t-input1 <> spaces)
|receive message and store parent thread handle
receive w-t-input1 from last thread
thread in w-t-phandle
end-perform
|tells parent it's started
send k-t-terminate to thread w-clock-t-phandle
...
|do something
...
|tells parent it's started
send k-t-terminate to thread w-clock-t-phandle
.
thread2 similar thread1.
in your case, I think you don't need to open files in thread, but do a normal perform and wait it ends executing.
hope it helps. Gio
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Some help with Threads please.

I may be missing something here - but why are you using a thread to open the files? If they MUST be open, then do not use a thread at all for the open files execution.

We implemented diary processes and similar processes with threads - but we have always made the diary process a separate program running in its own thread, each program can handle file opens itself at that point.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Some help with Threads please.

I was thinkin also to put it in a seperate program.
The reason for the thread to open files was because the section TEST-REMARK reads a file which is (still) not open and I don't know why that was. (file-error 47)
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Some help with Threads please.

I was thinkin also to put it in a seperate program.
The reason for the thread to open files was because the section TEST-REMARK reads a file which is (still) not open and I don't know why that was. (file-error 47)


One more reason to open files NOT in a thread but in a normal perform BEFORE starting test-remark thread:

perform open-files
perform thread test-remarks

Different thingh if you don't know WHEN thread-remarks file's can be opened, (for ex. due it's produced from another user or application) in this case you can use 2 threads with main thread as parent thread (structure I showed before):
thread-open-file loops "trying" to open files and when it succeds it communicates it to parent thread: this one than communicate to thread-remarks he can use file.
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.