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?

4

1 回答 1

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.

于 2012-08-22T14:49:56.057 回答