Results 1 to 4 of 4

Thread: Accessing deleted memory, Producer Consumer app

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Accessing deleted memory, Producer Consumer app

    Hi,

    I'm developing an application that contains 2 QThreads, one is the Producer and the other is the Consumer that have a ring buffer.

    The ring buffer is an array of objects.

    The Consumer does somethings on the object that is accessing and finally emits a signal with a pointer to that data to the Main Thread. The Main Thread takes the object(that is a pointer) and paints it's representation.

    I'm emitting pointers instead of objects to speed up the application.

    The problem is that when the Main Thread access to the data pointer, maybe it's being cleared(or filled) by the producer and then the application crash.

    Is there any way to know if the memory pointer don't contains data?

    I would like that Main Thread don't do anything if there is no real data.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing deleted memory, Producer Consumer app

    You are using a mutex to ensure that there is no race condition between your thread?
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Accessing deleted memory, Producer Consumer app

    Hi,

    Sorry for delay.

    You are using a mutex to ensure that there is no race condition between your thread?
    I'm using two QWaitConditions. The two threads work well without deadlocks. The problem is on visualization on the main thread where I don't want to use one more wait condition.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing deleted memory, Producer Consumer app

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    Sorry for delay.



    I'm using two QWaitConditions. The two threads work well without deadlocks. The problem is on visualization on the main thread where I don't want to use one more wait condition.

    Thanks,
    Sorry for the delay with my reply, but the product my company is working is close to master date, so it's some sort of busy weeks at the moment.

    Why not use another QWaitCondition? One way or the other you must tell your GUI Thread when it is allowed to fetch new data to render.
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

Similar Threads

  1. Speed up Producer Consumer Threads
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 29th February 2008, 18:38
  2. Producer Consumer
    By ^NyAw^ in forum Qt Programming
    Replies: 16
    Last Post: 17th November 2006, 19:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.