Skip to main content

[archive] Some help with Threads please.

  • November 28, 2007
  • 10 replies
  • 0 views

[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.

10 replies

[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.
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

[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.
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

[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.
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

[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.
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.

[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.
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.

[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.
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)

[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.
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)

[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.
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.

[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.
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.

[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.
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.