5

I want to create a simple Tic Tac Toe game, to be played between users of a SAP system.

I have a CL_TTT_MANAGER class with a SIGNUP method that assigns players to a game. My class is a shared-memory enabled class, because it's purpose is to potentially be accessed by all the users of a sap system.

The signup procedure is done using a very simple algorithm.

1:A "WAITING_FOR_PLAYERS" flag exists, and is set to ABAP_FALSE. initially. 2:When a first player calls "SIGNUP", the flag is set to "ABAP_TRUE". 3:When a second player calls "SIGNUP", the flag is set to "ABAP_FALSE" and the game instance is created.

The problem with my SIGNUP method is that it relies on state, namely it has to remember the name of the first player, and this is achieved using a private attribute.

For any of you who have worked with concurrency problems, you will spot a data race, namely that if right after the second player signs up, a third one also signs up, the name of the first player might be replaced with the name of the third.

How do i synchronize these things in abap? What mechanism do i have for this? I haven't encountered anything like this in the documentation (i've been studying only for 2 months). Do i have to implement this myself, or is there something to help me?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • well SAP is a company (like Oracle) and ABAP is their proprietary language (Like Java).... but used only for programing their systems. – vlad-ardelean Aug 22 '12 at 10:48

1 Answers1

3

This should not be a problem - before the third player is able to write to the shared memory area, he has to obtain a change handle, and he won't be able to get one as long as the second user still has a change lock set. See the docs for more detailed information on that topic.

Be aware that stable and reliable Shared Memory programming is one of the hardest tasks to accomplish in an ABAP environment (probably in any environment out there). I know from your other questions that you're relatively new to ABAP - it's ambitious to start off with shared objects so early.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • Thx for the info and the advice. I'm currently kinna responsible for my own training, so I might not always know when I step in an ABAP mine field during my coding adventures :). – vlad-ardelean Aug 22 '12 at 15:06
  • This is one, trust me. It's a selective mine field of the kind that will let central-instance-only development and testing systems pass and only blow up production environments with multiple application servers. – vwegert Aug 22 '12 at 15:10
  • Well thx for the warning. Haven't heard of the danger, so i'll keep an eye out. Would you happen to have any suggestions on how the communication between 2 instances of 2 separate users could occur in other ways (except for database acces)? – vlad-ardelean Aug 22 '12 at 15:19
  • Not really. You'll have to abuse something because the system wasn't designed for realtime interaction. – vwegert Aug 22 '12 at 15:43