Absent Member.
Absent Member.
979 views

Killing a thread

Jump to solution

I have created a thread using the CBL_CREATE_THREAD routine. However, when I attempt to kill the thread using CBL_THREAD_KILL it does not kill the thread. The thread remains running. My thread is defined as follows

01  THREAD-StatusBar-Routine  USAGE IS THREAD-POINTER.
 
and my call statement is
        CALL "CBL_THREAD_KILL" USING BY VALUE THREAD-StatusBar-Routine
           Move Return-Code To Thread-Return-Code.

The return code I get is
1009 Invalid parameter passed into a multi-threading library routine. A parameter has been detected that is not within the valid range, or that is inconsistent with the library routine.

Also in visual studio intellisense it says can not find method CBL_THREAD_KILL with this signature. Will create dynamic call.

What am I doing wrong?
Thanks

 

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Unfortunately I think the answer is that you're not doing anything wrong.  This is caused by a bug in our compiler, though coincidentally it's a bug that I just fixed.  This will work correctly in the 2.2 Update 1 version of the product.

As a work-around, try adding a variable of type System.IntPtr, and coding as follows:

      01  THREAD-StatusBar-Routine  USAGE IS THREAD-POINTER.

      01  IntPtr type System.IntPtr.

       *>CALL "CBL_THREAD_KILL" USING BY VALUE THREAD-StatusBar-Routine

       set IntPtr to Thread-StatusBar-Routine as type System.IntPtr

       CALL "CBL_THREAD_KILL" USING BY VALUE IntPtr

View solution in original post

0 Likes
3 Replies
Micro Focus Expert
Micro Focus Expert

Unfortunately I think the answer is that you're not doing anything wrong.  This is caused by a bug in our compiler, though coincidentally it's a bug that I just fixed.  This will work correctly in the 2.2 Update 1 version of the product.

As a work-around, try adding a variable of type System.IntPtr, and coding as follows:

      01  THREAD-StatusBar-Routine  USAGE IS THREAD-POINTER.

      01  IntPtr type System.IntPtr.

       *>CALL "CBL_THREAD_KILL" USING BY VALUE THREAD-StatusBar-Routine

       set IntPtr to Thread-StatusBar-Routine as type System.IntPtr

       CALL "CBL_THREAD_KILL" USING BY VALUE IntPtr

View solution in original post

0 Likes
Absent Member.
Absent Member.

Thanks That worked to kill the thread. Is there a way to send a message to a thread so that it can exit itself rather then just killing it?

0 Likes
Micro Focus Expert
Micro Focus Expert

Most thread communication can be handled using one of the synchronization primitives like a mutex, event, semaphore, monitor, etc.

You could also set a flag variable in the main thread in shared storage that the thread could then check to see if it should exit or not.

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.