Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Thread-Safety

Former Member
0 Kudos
1,076

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

1 ACCEPTED SOLUTION

markus_theilen
Participant
0 Kudos
111

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.

3 REPLIES 3

matt
Active Contributor
0 Kudos
111

Every thread will have its own ABAP memory space, so in that sense, safety is built in.

matt

Former Member
0 Kudos
111

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?

markus_theilen
Participant
0 Kudos
112

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.