Application Development and Automation 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: 
Read only

Thread-Safety

Former Member
0 Likes
1,817

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
Read only

markus_theilen
Participant
0 Likes
852

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
Read only

matt
Active Contributor
0 Likes
852

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

matt

Read only

Former Member
0 Likes
852

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?

Read only

markus_theilen
Participant
0 Likes
853

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.