Thread: multithreaded reeading and writing from buffer

  1. #1

    multithreaded reeading and writing from buffer

    The last years, 99% of my time I'm doing java so my C++ skills are well, erm, lets's say a bit at a low level.
    But I'm having a bit of a problem.
    I have a buffer that is accessed by two threads.
    One for reading and one for writing to the buffer (a vector).
    I'm pretty sure that I never write outside the memory allocated by the buffer.
    Due to performance issues we tryed removing 2 mutex locks and that worked CPU usage droped with 50%. We made the methods where we removed the mutex locks a bit smarter so we first check if we can safely read or not.
    That code isn't 100% safe because things can still go wrong between the check and the actual read.

    Now, about 2 or 3 times a day, we get a blue screen on Win XP and immediately after a reset of windows.
    Can this be the result of a push and pop on the same address?
    As far as I know, if I try to write beyond my allocated memory I would get an access violation message but windows wouldn't reset. Is this the same with reading and writing to the same address?

    I analysed the mini dumps from windows but that didn't give me any usefull information.

    I haven't been able to simulate it on the development machine with debuging capabilities nor am I allowed post any code.
    I also ran it with the ntsd but it hasn't crashed yet.

    Could the windows crash be related to our program or can it be a hardware fault (like a heat problem)?


    Thanks

    Maes
    Last edited by maes; 08-20-2007 at 01:39 AM.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I doubt you're causing the blue screen with that program unless your code is part of a driver (in which case unsafe thread code is a really baaaaaaaaad idea), or something else of that nature.

    Windows NT based systems, such as XP, are pretty stable and don't usually blue screen unless there is a driver problem or something hardware related.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree, it's very unlikely that you will crash the system with a user-mode application (unless you are talking to a borken driver of course).

    What is the bluescreen error you get?

    --
    Mats

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by maes View Post
    Could the windows crash be related to our program or can it be a hardware fault (like a heat problem)?
    Unlikely, since the problem only appeared once you changed your code. You might spend all week speculating why Windows crashes, but that's probably not a good use of your time since you might find another box where it doesn't crash. Just fix the code and chalk it up to "Who knows with Windows."

  5. #5
    Quote Originally Posted by matsp View Post
    I agree, it's very unlikely that you will crash the system with a user-mode application (unless you are talking to a borken driver of course).

    What is the bluescreen error you get?

    --
    Mats

    The blue screen disapears to quickly the computer resets immediatly after.
    But I think you're all right. Last night I had the original program running and it still did a reboot.
    So I doubt it will be a bug in our program.

    Thanks for the help,

    Maes

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    if i do not remember wrong you can download the tweakui utility from microsoft and disable the immediate reboot with it. then you are able to read the blue screen message.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by pheres View Post
    if i do not remember wrong you can download the tweakui utility from microsoft and disable the immediate reboot with it. then you are able to read the blue screen message.
    Yes - in fact, it doesn't take a TweakUI either - just go to Control-Panel->System->Advanced and unclick "Automatically reboot" - or if you have a minidump, you should be able to see the fault that caused the dump.

    --
    Mats

Popular pages Recent additions subscribe to a feed