ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Calling a function of another job

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling a function of another job

    Hello everyone.
    There is a C program that implements some function. This program uses the spawn function to start another program and pass a pointer to its function into it. Can the second program call a function from the first program on this pointer?

  • #2
    The actual code is shared across jobs, but the activation is not. So, I'm not exactly sure what would happen... I wouldn't recommend it, though. Even if you get it working, it's going to be really hard for the next programmer to try to understand.

    Depending on what you're doing, perhaps pthreads would be a better fit?

    Comment


    • #3
      Scott, you are amazingly perspicacious!
      Yes, I really need it to reinvent multithreading. The point is that using pthread requires the job to be created with multithreading support. However, all our services for launching jobs create them by default (without multithreading support). Nobody will change this mechanism for my applications, and it is impossible to change the multithreading mode of a running job.

      Comment


      • #4
        Perhaps you can submit a new job that has multi-threaded support, run the pthreads in that, and send the results back to the original job via data queue or similar?

        Comment


        • #5
          Scott, yes, I thought about it. But the point is, I am creating general purpose code (simply put, I am creating a library). The path of launching a separate task is not quite suitable here, since it involves creating a separate program with code that performs a specific task. But I don’t know what exactly the library user will need to do.

          I planned to create a program, for example, named "thread" with an activation group * CALLER. In the library, create a class with the same name (I am making the library in C ++). To use it, you need to create an object of the class, specify the "stream" function and start. The class will call the "thread" program, passing in a function pointer.

          But we need to find out whether it is possible to call a function from another from one program, provided that they have a common activation group.

          Comment


          • #6
            Originally posted by d7d1cd_ View Post
            But we need to find out whether it is possible to call a function from another from one program, provided that they have a common activation group.
            Activation groups are a part of the job. Since you're spawning a new job, it will automatically be a separate activation group.

            Comment


            • #7
              I think we need more information before we can really help.
              • What is the called program going to do with the pointer?
              • What is the pointer pointing to?
              When we know that, we might be able to suggest ways to do what you want, without trying to pass a pointer from one job to another.

              Comment


              • #8
                Originally posted by Scott Klement View Post
                Activation groups are a part of the job. Since you're spawning a new job, it will automatically be a separate activation group.
                Scott, but the called program will be created with the parameter ACTGRP = * CALLER. Wouldn't the caller and the called program have more than one activation group in this case?

                Comment


                • #9
                  Originally posted by Barbara Morris View Post
                  What is the called program going to do with the pointer?
                  The called program, given the function pointer passed to it, will call this function.


                  Originally posted by Barbara Morris View Post
                  What is the pointer pointing to?
                  From the first answer, it follows that the pointer points to a function.

                  Comment


                  • #10
                    Oops, sorry, I lost track of your first post while reading the later posts. You were clear that it was a function pointer.

                    Comment

                    Working...
                    X