Concurrent access to changing data structure

I would like to design a data structure that would allow multiple read only threads to access it but periodically allow the structure to be modified or completely refreshed by one other thread. I would prefer to not have to synchronize access to the structure by the read only threads just to allow one thread to modify it once in a while. Can the object be locked and the other threads blocked just when the one thread is modifying the structure until it completes?
Is there a common or recommended design for this situation?

So you want it to block while the writer is writing, but not otherwise, correct?
Check out Doug Lea's concurrency package. I've never used it, but it seems quite popular and I gather it's got a lot of handy tools. It might have what you're looking for. Google for it. It (or something based on it) might even be included in 1.5/5.0, IIRC.
Barring that, I think that if your reads are quick (i.e., just retrieving a single value) and you don't have a ton of threads all doing a lot of very, very frequent reads, then you can just synchronize all access to the structure's state. Uncontended locks are quick to obtain and release, so unless your reads take a relatively long time or they're very densely packed in time, you won't get many collisions.
If you do need to implement something like this, then what I'm thinking of is to have a flag that indicates whether there's a read or write going on. If there's a read going on, other reads can go on, but no writes. If there's a write going on, no other writes or reads can occur. Access to the flag would have to be synchronized, readers/writers would have to wait/notify each other, so you might not end up saving that much performance-wise anyway. I'm not even sure if there's a good way to make it work--it might just end up being an overcomplicated, non-working double-checked lock.
Start with just syncing all access to the structure's state--both read and write--and then run some tests to see if your performance requirements are met.

Similar Messages

  • How to synchronize concurrent access to static data in ABAP Objects

    Hi,
    1) First of all I mwould like to know the scope of static (class-data) data of an ABAP Objects Class: If changing a static data variable is that change visible to all concurrent processes in the same Application Server?
    2) If that is the case. How can concurrent access to such data (that can be shared between many processes) be controlled. In C one could use semaphores and in Java Synchronized methods and the monitor concept. But what controls are available in ABAP for controlling concurrent access to in-memory data?
    Many thanks for your help!
    Regards,
    Christian

    Hello Christian
    Here is an example that shows that the static attributes of a class are not shared between two reports that are linked via SUBMIT statement.
    *& Report  ZUS_SDN_OO_STATIC_ATTRIBUTES
    REPORT  zus_sdn_oo_static_attributes.
    DATA:
      gt_list        TYPE STANDARD TABLE OF abaplist,
      go_static      TYPE REF TO zcl_sdn_static_attributes.
    <i>* CONSTRUCTOR method of class ZCL_SDN_STATIC_ATTRIBUTES:
    **METHOD constructor.
    *** define local data
    **  DATA:
    **    ld_msg    TYPE bapi_msg.
    **  ADD id_count TO md_count.
    **ENDMETHOD.
    * Static public attribute MD_COUNT (type i), initial value = 1</i>
    PARAMETERS:
      p_called(1)  TYPE c  DEFAULT ' ' NO-DISPLAY.
    START-OF-SELECTION.
    <b>* Initial state of static attribute:
    *    zcl_sdn_static_attributes=>md_count = 0</b>
      syst-index = 0.
      WRITE: / syst-index, '. object: static counter=',
               zcl_sdn_static_attributes=>md_count.
      DO 5 TIMES.
    <b>*   Every time sy-index is added to md_count</b>
        CREATE OBJECT go_static
          EXPORTING
            id_count = syst-index.
        WRITE: / syst-index, '. object: static counter=',
                 zcl_sdn_static_attributes=>md_count.
    <b>*   After the 3rd round we start the report again (via SUBMIT)
    *   and return the result via list memory.
    *   If the value of the static attribute is not reset we would
    *   start with initial value of md_count = 7 (1+1+2+3).</b>
        IF ( p_called = ' '  AND
             syst-index = 3 ).
          SUBMIT zus_sdn_oo_static_attributes EXPORTING LIST TO MEMORY
            WITH p_called = 'X'
          AND RETURN.
          CALL FUNCTION 'LIST_FROM_MEMORY'
            TABLES
              listobject = gt_list
            EXCEPTIONS
              not_found  = 1
              OTHERS     = 2.
          IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL FUNCTION 'DISPLAY_LIST'
    *       EXPORTING
    *         FULLSCREEN                  =
    *         CALLER_HANDLES_EVENTS       =
    *         STARTING_X                  = 10
    *         STARTING_Y                  = 10
    *         ENDING_X                    = 60
    *         ENDING_Y                    = 20
    *       IMPORTING
    *         USER_COMMAND                =
            TABLES
              listobject                  = gt_list
            EXCEPTIONS
              empty_list                  = 1
              OTHERS                      = 2.
          IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
      ENDDO.
    <b>* Result: in the 2nd run of the report (via SUBMIT) we get
    *         the same values for the static counter.</b>
    END-OF-SELECTION.
    Regards
      Uwe

  • Changing data structure in the receiver SOAP adapter

    I was wondering whether it is possible to have changing data structure in terms of one receiver SOAP adapter so I could sent data type 1 and 2 to a single XI web service enabled URL and make conditional parsing in terms of the received message ?
    I have a receiver SOAP adapter that ideally should be able to receive two different types of messages. But SOAP adapter is fixed to a sigle message interface that naturally has it's data structure set to just one type. I can just create conditions in terms of the data type 1 message that has been defined in the design side.
    Is it possible achieve this with just one SOAP receiver adapter?

    Henri,
    Please go through the note: 856597 (Quesiton NO 9)
    -Naveen.

  • Clusters as data structures

    I am looking for the best and simplest way to create and manage data structures in Labview.
    Most often I use clusters as data structures, however the thing I don't like about this approach is that when I pass the cluster to a subroutine, the subroutine needs a local copy of the cluster.
    If I change the cluster later (say I add a new data member), then I need to go through all the subroutines with local copies of the cluster and make the edit of the new member (delete/save/relink to sub-vi, etc).
    On a few occasions in the past, I've tried NI GOOP, but I find the extra overhead associated with this approach cumbersome, I don't want to have to write 'get' and 'set' methods for every integer and string, I like being able to access the cluster/object data via the "unbundle by name" feature.
    Is there a simple or clever way of having a single global reference to a data object (say a cluster) that is shared by a group of subroutines and which can then be used as a template as an input or output parameter? I might guess the answer is no because Labview is interpreted and so the data object has to be passed as a handle, which I guess is how GOOP works, and I have the choice of putting in the extra energy up front (using GOOP) or later (using clusters if I have to edit the data structure). Would it be advisable to just use a data cluster as a global variable?
    I'm curious how other programmers handle this. Is GOOP pretty widely used? Is it the best approach for creating maintainable LV software ?
    Alex

    Alex,
    Encapsulation of data is critical to maintaining a large program. You need global, but restricted, access to your data structures. You need a method that guarantees serial, atomic access so that your exposure to race conditions is minimimized. Since LabVIEW is inherently multi-threaded, it is very easy to shoot yourself in the foot. I can feel your pain when you mention writing all those get and set VIs. However, I can tell you that it is far less painful than trying to debug a race condition. Making a LabVIEW object also forces you to think through your program structure ahead of time - not something we LabVIEW programmers are accustomed to doing, but very necessary for large program success. I have use three methods of data encapsulation.
    NI GOOP - You can get NI GOOP from the tutorial Graphical Object Oriented Programming (GOOP). It uses a code interface node to store the strict typedef data cluster. The wizard eases maintenance. Unfortunately, the code interface node forces you through the UI thread any time you access data, which dramatically slows performance (about an order of magnitude worse than the next couple of methods).
    Functional Globals - These are also called LV2 style globals or shift register globals. The zip file attached includes an NI-Week presentation on the basics of how to use this approach with an amusing example. The commercial Endevo GOOP toolkit now uses this method instead of the code interface node method.
    Single-Element Queues - The data is stored in a single element queue. You create the database by creating the queue and stuffing it with your data. A get function is implemented by popping the data from the queue, doing an unbundle by name, then pushing the data back into the queue. A set is done by popping the data from the queue, doing a bundle by name, then pushing the data back into the queue. You destroy the data by destroying the queue with a force destroy. By always pulling the element from the queue before doing any operation, you force any other caller to wait for the queue to have an element before executing. This serializes access to your database. I have just started using this approach and do not have a good example or lots of experience with it, but can post more info if you need it. Let me know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Using a single data structure in a desktop application

    Hello,
    I am programming an application that needs to constantly access a data structure, for instance to add / edit / update / search data. Several graphical user interfaces need to modify this data structure. I was wondering of easy ways to use the data structure throught the whole application. One solution I found was to use the singleton pattern for my data structure, though lots of people have recommended me to avoid using that pattern. What are better ways of accessing that single data structure from all of those GUIs ?
    Thank you,
    Alfredo

    Not that there is anything wrong with a Singleton pattern, but I don't see how it would help you in this case.
    Just create the DataStructure and let every GUI that need to use it have a reference to it.

  • EFS, password change denies access to encrypted data

    Hi,
    Has anyone had the issue with admin changing users password in Console One
    resulting in users not being able to access their encrypted data.
    Laptop users are using EFS to encrypt their data.
    These users have WinXPPro SP2 and we are running ZfD 6.5SP2.
    I have found IR 1 for ZfD 6.5 SP2 which includes TID3003874 "Personal IE
    certificates and EFS stop working after password change" however this does
    not fix the issue.
    Could someone explain in more detail what this fix does as I may have
    misunderstood what this fix is.
    Regards,
    Eric.

    I know this is an old thread, but I thought it would be best to those who
    found it realized that the best method for addressing this issue may be
    found here:
    http://www.novell.com/support/viewCo...rnalId=3724689
    However the MS article could still be useful for some.
    Craig Wilson - MCNE, MCSE, CCNA
    Novell Support Forums Volunteer Sysop
    Novell does not officially monitor these forums.
    Suggestions/Opinions/Statements made by me are solely my own.
    These thoughts may not be shared by either Novell or any rational human.
    "ghoskins" <[email protected]> wrote in message
    news:[email protected]..
    >
    > I'm having the same problem. I ran acrosss this Microsoft KB and it
    > seems to fix the issue. I'm not certain this is the best security
    > practices, but it does work.
    >
    > 'User cannot gain access to certificate functionality after password
    > change or when using a roaming profile'
    > (http://support.microsoft.com/default...b;en-us;331333)
    >
    >
    > --
    > ghoskins
    > ------------------------------------------------------------------------
    > ghoskins's Profile: http://forums.novell.com/member.php?userid=12306
    > View this thread: http://forums.novell.com/showthread.php?t=215857
    >

  • I am being asked to upgrade to iCloud Drive but indications are that I will not be able to access up to date details on any of my documents on my Mac without going into iCloud first.  Have I got this interpretation right or can I save changes to acce

    I am being asked to upgrade to iCloud Drive but indications are that I will not be able to access up to date details on any of my documents on my Mac without going into iCloud first.  Have I got this interpretation right or can I save changes to access the new versions on my iMac?

    That is Apple's statement:
    Using iWork with iCloud Drive - Apple Support
    Options for iWork customers
    You can upgrade to iCloud Drive today if you want to keep your documents up to date in iOS 8 and OS X Yosemite, and you want to use the iWork web apps on iCloud.com and the Share via iCloud feature.
    You can upgrade to iCloud Drive later if you want to keep your documents up to date with your apps on iOS 7 or earlier and OS X Mavericks or earlier.
    Upgrade to iCloud Drive today
    To access the most recent versions of your documents from a Mac with OS X Mavericks or earlier, you’ll need to go to iCloud.com and access Pages, Numbers, and Keynote from there. On a PC, you can install iCloud for Windows and set up iCloud Drive.
    If you upgrade to iCloud Drive now:
    Your documents will keep up to date across devices with iOS 8, Macs with OS X Yosemite, PCs with iCloud for Windows, and iCloud.com.
    Your documents will no longer keep up to date on devices with iOS 7 and Macs with OS X Mavericks or earlier.
    You’ll be able to use the iWork web apps on iCloud.com.
    You’ll be able to use the Share via iCloud feature with iOS 8, OS X Yosemite, and iCloud.com.
    Documents you previously shared via iCloud will be accessible to collaborators.
    Upgrade to iCloud Drive later
    Note that until you upgrade your iCloud account to iCloud Drive, you won’t be able to use the iWork web apps on iCloud.com or the Share via iCloud feature.     If you don’t upgrade to iCloud Drive at this time:
    Your documents will keep up to date across devices with iOS 8 and across devices with iOS 7 and Macs with OS X Mavericks or earlier.
    You won’t be able to use the iWork web apps on iCloud.com.
    You won’t be able to use the Share via iCloud feature.
    Documents you previously shared via iCloud won’t be accessible to collaborators until you upgrade to iCloud Drive.

  • Changing data types of  fields in structures

    Hello,
       Currently we are working for upgrade to ECC 6.0 .
       In some transactions we are using BAPI_MATERIAL_SAVEDATA to create material.
      We have some additional fields in MARA and MARC table , which we fill using BAPI_TE_MARA and BAPI_TE_MARC structures.
        In these structures we have different data types for fields earlier in 4.6C
    Now this function module is only working if we change  data types of  fields in these structures only to char type. It is going for dump , if we maintain any other data type.
      Could any body tell me why should we change for char data type ?
    Regards,
      SATYA

    Hi,
    Check enhancement category (Extras --> Enhancement Category) for structures before enhancement. For example, for BAPI_TE_MARA structure, enhancement category is given as character type or numeric type. That means you can add the fields of data type only C and N. No other data types are allowed. If you select as not classified then you can add any data type. This option plays important role while enhancement.
    Regards,
    Prasanth

  • Storing a lot of data in an indexed data structure for quick access.

    I'm designing an app. which will need to store a large amount of data in memory. Records will be flowing into the app. via a socket. The app will receive about 30 records/second which is about 108,000 records/hour and about 600,000 records/day. I need to store the records in an indexed data structure so that I can access them quickly. For example, at 9:00am I will need to access records received at 8:30am, 8:35am, 8:40am, etc. This program will be multithreaded and as I understand Vector is the only data structure that is thread safe. Is Vector my only choice? How do I access objects in a Vector using an index? Is there something better that I can use?

    Is Vector my only choice?If you want to access the objects by key then you should use something like a HashMap. But if you want to access them by an array index then an ArrayList would be more appropriate.
    as I understand Vector is the only data structure that is thread safeYou can get a thread-safe version of any Collection object by using the Collection.synchronizedCollection method.
    How do I access objects in a Vector using an index? I'd suggest you read the API documentation. And probably the Sun tutorial on Collections at http://java.sun.com/docs/books/tutorial/collections/index.html
    600,000 records/day. Unless you plan to dump old data after a short period of time, you may want to consider using a database to avoid running out of memory.

  • Accessing tcp_t data structure

    I need to access tcp_t datastructure which is implemented in Solaris 10,
    how could it can be programmed in c to access tcp_t data structure.

    Look at /usr/include/inet/tcp.h - it defines the structure tcp_t.
    Add the following line to your source file:
    #include <inet/tcp.h>
    I'm not sure that this information is exactly what you are asking for.
    Probably you can find good examples of source code on google.com
    Thanks.
    Nik

  • Shared data - concurrent access

    Entity beans are best used when shared data is being concurrently accessed.
    Could you please clarify this statement . How does it different than shared data - concurrent access by jdbc DAO class ?

    jverd wrote:
    I have no idea what you're asking. I cannot provide clarification until you do.Ok. let me explain further. my question is , is it a good idea that whenever we need shared concurrent data access in a application Entity bean is the best ? Why? does it really outsmart the jdbc DAO access methodology whenever it comes to the realm of shared concurrent data access ?
    For example: I can think of a system e.g online auction house application. This needs concurrent shared data access ..right ?
    Do you think use of Entity bean is best here instead of jdbc DAO access methodology ? Why ?

  • [Access 2010] Change default formats for data types

    Whenever I import data, the default format for Boolean data types is "-1,0." I know how to subsequently change this format to "Yes/No," but I'd like to change the default
    setting to "Yes/No." Is this possible?
    Thanks in advance.

    Hi,
    I found you post the same question in other place and got the advice. I agree with Mr. Kees suggestion. The data type is a build-in default setting with Access, we can't change it. We may try the workaround via VBA to test.
    http://forums.cnet.com/7723-6129_102-627633/access-2010-change-default-formats-for-data-types/#message5617496
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Have a good time.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Risks of changing the field length of data structure of a Cluster Table

    Hello,
    We are on ECC 604 and had implemented HR & Travel Management. Reporting on these applications is done in BI. We use ESS and & Mobile Travel for  time, travel expenses, etc and use PCLn clusters.
    There is business need to change the length of a field from 20 to 40 for the data structure PTK** of cluster table PCL1. 
    We are exploring various options to avoid core modifications.
    We are also assessing the risks associated with changing the field length.
    I  am asking you for your opinion about the risks associated with changing the field length of a data structure of cluster table.
    Thanks & Regards,
    Manoj K Pingali

    Recently, we came across the same situation where we had to change the length of a field. Let me explain you what precautions we had taken during that time.
    1. Apply the where use list of that table/ Field and check whether it has been used in some program and FM or not. If yes then check one more thing that check the TYPE of another variables on which system has populating data (move, write or in FM parameters). if you will not consider this then you can land you in big trouble. (Conversion dump)
    2. Ask the basis to take a dump of the production, quality and data for the safer side if something does not go right.
    Now, you can do the changes in your development system and then adjust the database and see the impact of it.
    Hopefully, you will not come across any difficult situation in this changes.
    Thanks.
    Anurag

  • How to access data structures in C dll from java thru JNI?

    We have been given API's( collection of C Functions) from some vendor.
    SDK from vendor consist of:
    Libpga.DLL, Libpga.h,Libpga.lib, Along with that sample program Receiver.h (i don't know its written in C or C++), I guess .C stnads for C files?
    Considering that I don't know C or C++ (Except that I can understand what that program is doing) & i have experience in VB6 and Java, In order to build interface based on this API, I have two option left, Use these dll either from VB or Java.
    As far as I know, calling this DLL in VB requires all the data structures & methods to be declared in VB, I guess which is not the case with Java (? I'm not sure)
    I experiemnted calling these function from Java through JNI, and I successfully did by writting wrapper dll. My question is whether I have to declare all the constants & data structures defined in libpga.h file in java, in order to use them in my java program??
    Any suggesstion would be greatly appreciated,
    Vini

    1. There are generators around that claim to generate suitable wrappers, given some dll input. I suggest you search google. Try JACE, jni, wrapper, generator, .... Also, serach back through this forum, where there have been suggestions made.
    2. In general, you will need to supply wrappers, and if you want to use data from the "C side" in java, then you will need java objects that hold the data.

  • Is timesten still using T-tree as data structure?

    I just come across this paper - http://www.memdb.com/paper.pdf , this researcher do some experiments and showing that using concurrent B-tree algorithm is actually faster than T-tree operation. How do you think about this paper? Do you think actually he is using a inefficient algorithm to access T-tree? Or, Timesten already know the limitation of T-tree and have changed the internal data-structure?

    Yes, we are aware of the comparisons between T-Trees, concurrent B-trees etc. At the moment TimesTen still uses T-trees but this may change in the future :-)
    Chris

Maybe you are looking for