Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:20:59+00:00 2026-05-31T18:20:59+00:00

I currently have two threads running in my program: Main thread – Grabs image

  • 0

I currently have two threads running in my program:

  1. Main thread – Grabs image from a webcam, stored in a CVD image. Does processing on this image.

  2. Server thread – sends the full image data stored in the above CVD image to its clients using named pipes.

When I run my program it works for a very short while before crashing with the following exception:

0xC000005: Access violation reading location 0x0000000

Which I assume is because my server thread is attempting to access the image at the same time as the main thread.

I haven’t done any concurrent programming before (this is my first time) but I have a vague idea about how to solve it at the moment.

My plan is to have some sort of lock that prevents access to the image from the main thread when the server is preparing to send it to the client. However I realised there might be a problem where the server thread constantly keeps the resource as the client is constantly requesting a new frame. So I am thinking to only respond to the client whenever a new frame is grabbed from the webcam to avoid the blocking issue above.

To sum this up:

Main thread:

1. If Image is available
   then - Lock image, copy over new data from webcam, release image
   else - goto 1
2. Do processing

Server:

1. Receive request for new frame from client
2. If (haven't sent the current frame yet)
   then - Lock CVD image access, send over frame, release image.
   else - wait until new image available.
3. goto 1

My question is, would this be a suitable solution? and what do I need in order to implement this? i.e. how do I stop execution of certain parts of my code whilst another thread is executing a part of its own code.

Some more info:

  1. I am using VS2010 C++
  2. The client is in C# and there is only 1 client.
  3. I am accessing the image data from the CVD image using image[x][y] which returns a byte value representing the intensity of the image.
  4. There is a copyTo() function available with the CVD image. It seems to do a memory copy of the image to create a new object with the same data. Would this be useful?
  5. I cannot run the program in debug mode because I am working off an existing codebase with no debug mode set.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:21:00+00:00Added an answer on May 31, 2026 at 6:21 pm

    I would use a circular buffer so I could be reading one frame while writing a different one to clients, assuming you don’t want to drop frames.

    Look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms682530(v=vs.85).aspx for info on Windows Critical Sections.

    Finally, if you have the existing code, why can’t you turn debug info on and rebuild? Otherwise you’re shooting in the dark trying to find the cause of this crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my project running two separate threads (one for MFC operations, like
I am currently making an application in which I have two threads running, and
I'm running SourceSafe and I have two branches of my code. I'm currently using
Okay. I want to have two threads running. Current code: public void foo() {
I currently have two text boxes which accept any number. I have a text
I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including
I currently have two panels within another large panel. The left panel is for
I (currently) have two forms, one that needs to call the other. In other
All, I currently have two projects that are under SourceSafe that I am unable
Currently I have two MediaWikis, one a slightly older version than the other. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.