locked
Global variable getting corrupted RRS feed

  • Question

  • Hi,

    This is crazy :) I have this global structure with a unsigned char property which is used by several threads.

    It is only initialized once and nowhere in the code the value is assigned.

    It has run perfect for many years in all UAT and Prod servers.

    Now moving service to new Prod server (windows 2008, redistributable c++ 2010) causes this global variable to get corrupted after some running time. The value chages from 1 to a random value i.e. 19123.

    The issue is not reproducible in any other server.

    The structure is passed by reference to several threads. My current theory is that we shouldn't share a global structure by several threads but that does not explain why code ran fine for years.

    Any clue on what to look next or how to troubleshoot? Other than write to log :)

    Thanks

    Lucas

    Tuesday, October 11, 2016 9:37 PM

Answers

  • Hi HGG42,

    thanks for posting here.

    >>Any clue on what to look next or how to troubleshoot? Other than write to log :)

    For this case, I suggest you use a constructor to initial your shared structure. For example:

    struct Test
    {
    	unsigned char cTest;
    	...
    
    	Test()
    	{
    		cTest = 1;
                    ...
    	}
    };

    If you want to troubleshoot this , you could specify a Data Breakpoints to this variable. If it's value changed, you could get to the statement. Here is a document for you as a reference.

    https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/14/data-breakpoints/

    Hope this could be help of you.

    Best Regards,
    Sera Yu



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    • Proposed as answer by Baron Bi Thursday, October 13, 2016 2:03 AM
    • Marked as answer by HGG42 Thursday, October 13, 2016 4:37 PM
    Wednesday, October 12, 2016 2:39 AM

All replies

  • Hi HGG42,

    thanks for posting here.

    >>Any clue on what to look next or how to troubleshoot? Other than write to log :)

    For this case, I suggest you use a constructor to initial your shared structure. For example:

    struct Test
    {
    	unsigned char cTest;
    	...
    
    	Test()
    	{
    		cTest = 1;
                    ...
    	}
    };

    If you want to troubleshoot this , you could specify a Data Breakpoints to this variable. If it's value changed, you could get to the statement. Here is a document for you as a reference.

    https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/14/data-breakpoints/

    Hope this could be help of you.

    Best Regards,
    Sera Yu



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    • Proposed as answer by Baron Bi Thursday, October 13, 2016 2:03 AM
    • Marked as answer by HGG42 Thursday, October 13, 2016 4:37 PM
    Wednesday, October 12, 2016 2:39 AM
  • Hi Sera,

    Many thanks for your reply! I'm marking this as answer because that's very helpful anyway.

    However turns out one of our assumptions were wrong, we did activate a new code flow in the new server and the bug was in the new flow.

    We were writing to a string array a value that exceeds the array length and then struct got corrupted!

    Thanks

    Thursday, October 13, 2016 4:37 PM