Jump to content

Does “shared memory” have a read-write lock mechanism to avoid synchronous read-write problems?


Recommended Posts

Hello everyone, I am trying to write a small tool that reads hardware information from the shared memory of AIDA64. I use python's MMAP library to operate.I found that mmap can obtain the target XML text when reading, but errors often occur during the XML parsing in the subsequent steps.The manifestation of this error is that the XML parser often cannot find a properly closed tag.In manual inspection, I found that this kind of error can be manifested as follows:

1.<pwr>**********</pwr> wr>

2.<value>**********</vaalue>

3.<iid>**********</id>

These errors look like I am reading while AIDA64 is writing to the shared memory area. The data read in this way is not a complete frame(Therefore, the structure of the data as XML may not be complete due to misalignment and other reasons).

The test code I used for reading is as follows:

while(1):
    try:
        with mmap.mmap(fileno=-1, length=12288, tagname="AIDA64_SensorValues") as AIDA64data:
            string = AIDA64data.read().strip(b"\0").decode(encoding="gbk")
            string = f"<AIDA64>{string}</AIDA64>"
            dict_xml = xmltodict.parse(string)
    except Exception as e:
        print(e)
        continue

Does AIDA64 provide a function that shows a locked state when it accesses shared memory?Or is there a way to avoid reading while writing?

I am a rookie programmer, maybe this problem can be realized by using some advanced functions of the program, please help me, thanks! :)

 

Link to post
Share on other sites
  • 3 weeks later...
On 3/18/2021 at 5:53 AM, kombi said:

Hello everyone, I am trying to write a small tool that reads hardware information from the shared memory of AIDA64. I use python's MMAP library to operate.I found that mmap can obtain the target XML text when reading, but errors often occur during the XML parsing in the subsequent steps.The manifestation of this error is that the XML parser often cannot find a properly closed tag.In manual inspection, I found that this kind of error can be manifested as follows:

1.<pwr>**********</pwr> wr>

2.<value>**********</vaalue>

3.<iid>**********</id>

These errors look like I am reading while AIDA64 is writing to the shared memory area. The data read in this way is not a complete frame(Therefore, the structure of the data as XML may not be complete due to misalignment and other reasons).

The test code I used for reading is as follows:


while(1):
    try:
        with mmap.mmap(fileno=-1, length=12288, tagname="AIDA64_SensorValues") as AIDA64data:
            string = AIDA64data.read().strip(b"\0").decode(encoding="gbk")
            string = f"<AIDA64>{string}</AIDA64>"
            dict_xml = xmltodict.parse(string)
    except Exception as e:
        print(e)
        continue

Does AIDA64 provide a function that shows a locked state when it accesses shared memory?Or is there a way to avoid reading while writing?

I am a rookie programmer, maybe this problem can be realized by using some advanced functions of the program, please help me, thanks! :)

We don't use locking for our shared memory, but we also haven't got any complaints about it working incorrectly.  When we use OpenFileMapping / MapViewOfFile, no such anomaly occurs at all.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...