2009 Feb 04 12:37 PM
Hello,
I'm currently thinking about implementing a simple class to handle parallel processes (much like the function SPTA_PARA_PROCESS_START_2). But while doing so I've discovered the question if there is a way to ensure thread-safety for Attributes/Methods in ABAP, or if they are thread-safe by design?
Thanks and Regards,
Carsten
2009 Feb 11 10:48 AM
Hi!
Matt's answer is still correct.
You spawn the concurrent processes in one mode (1 mode = 1 thread, no concurrency here) which excute the main calculation concurrently in different worker processes then. When the callbacks for returning the results of these calcualtions are called, they are executed in this one single starting mode which can't execute in parallel by design, so the given callback form is executed sequentially for all spawned "worker threads". You don't need any synchronization mechanism to prevent data corruption for this example because the callback form always executes in one given memory space.
For further reading, have a look at the documentation of the keyword WAIT or CALL FUNCTION...STARTING NEW TASK in general. Or, nearly surprising because there is one, have a sharp loop at the present documentation of the function you named.
2009 Feb 05 9:54 AM
Every thread will have its own ABAP memory space, so in that sense, safety is built in.
matt
2009 Feb 10 8:11 AM
Well, but the Threads/Processes will join at some time, where they call the same callback-routine in a single memory space to return their results - and what happens if they write at the same time into the same internal table?
2009 Feb 11 10:48 AM
Hi!
Matt's answer is still correct.
You spawn the concurrent processes in one mode (1 mode = 1 thread, no concurrency here) which excute the main calculation concurrently in different worker processes then. When the callbacks for returning the results of these calcualtions are called, they are executed in this one single starting mode which can't execute in parallel by design, so the given callback form is executed sequentially for all spawned "worker threads". You don't need any synchronization mechanism to prevent data corruption for this example because the callback form always executes in one given memory space.
For further reading, have a look at the documentation of the keyword WAIT or CALL FUNCTION...STARTING NEW TASK in general. Or, nearly surprising because there is one, have a sharp loop at the present documentation of the function you named.