473,769 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

access violation reading location when using WaitForMultiple Objects

4 New Member
Hi,

I am writing a multi-threads encryption application. The idea of the code is to create a number of threads to encrypt files. I have a thread pool say the maximum threads is 10. If the number of tasks (number of files waiting to be encrypted) is larger than the thread pool size, I first create 10 new threads to execute the encryption function. Then I wait for any of the threads to be signaled in the thread pool using WaitForMultiple Objects with WaitAll bit set to false. Then I close the handle to that thread and create a new thread on the slot. After all tasks are done, I call WaitForMultiple Objects with WaitAll bit to TRUE and wait all threads to terminate.

The error, access violation reading location 0x00000000 occurs in the last step. Trying to debug it, the memcpy.asm code pops up and terminates at the last line: rep movsd

Expand|Select|Wrap|Line Numbers
  1. Dword_align:
  2.         test    edi,11b         ;U - destination dword aligned?
  3.         jnz     short CopyLeadUp ;V - if we are not dword aligned already, align
  4.  
  5.         shr     ecx,2           ;U - shift down to dword count
  6.         and     edx,11b         ;V - trailing byte count
  7.  
  8.         cmp     ecx,8           ;U - test if small enough for unwind copy
  9.         jb      short CopyUnwindUp ;V - if so, then jump
  10.  
  11.         rep     movsd           ;N - move all of our dwords
I tried to debug it and found out a very strange thing. When the executed task jumps over the 10th, a WaitForMultiple Objects(with waitall = false) is called. I can therefore find out which thread got signaled (for example thread number 5). Then a new thread is created for the task number 11. I can see the thread ID of this newly created thread is different from the first 5th threads, but the return value of CreateThread which is the handle of this thread is still equal to the handle of the 5th thread.

Thanks
Nov 14 '07 #1
3 8058
Pinux
4 New Member
Sorry. I found out the error when studying the call stack. It has nothing to do with the multi-thread programming but because the key used in the encryption function is destroyed when any of the encryption function is finished within a thread. The memory access violation was caused by reading an empty encryption key:-)

cheers
Nov 14 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
Well, thanks for posting anyway, please feel free to post again if you run into anything else.
Nov 14 '07 #3
nawito
2 New Member
I run to the same error because i send to WaitForMultiple Objects an handle pointer not an static array. Remember max processes over XP is 64 process.
See the following example, it works perfectly:

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <process.h>
  7.  
  8. // Secound Thread function
  9. void ThreadProc(void *param);
  10.  
  11.  
  12. // First thread 
  13. int main()
  14. {
  15.  
  16.     int n;
  17.     int i;
  18.     int val = 0;
  19.     HANDLE handle;
  20.     DWORD dwRetVal ;    
  21.  
  22.     printf("\t Thread Demo\n");
  23.     printf("Enter the number of threads : ");
  24.     scanf("%d",&n);
  25.  
  26.     while (n>MAXIMUM_WAIT_OBJECTS)
  27.     {
  28.         printf("Enter the number of threads smaller than 64 : ");
  29.         scanf("%d",&n);
  30.     }
  31.         {
  32.         //HANDLE *pArrayInt= (HANDLE *)malloc (n);
  33.         HANDLE pArrayInt[MAXIMUM_WAIT_OBJECTS];
  34.  
  35.         for(i=0;i<n;i++)
  36.         {
  37.             val = i+1;
  38.             handle = (HANDLE) _beginthread( ThreadProc,0,&val); // create thread
  39.             pArrayInt[i] = handle;
  40.             printf ("%d Handle \n",handle);
  41.         }
  42.         dwRetVal =WaitForMultipleObjects((DWORD)n,pArrayInt,TRUE,INFINITE);
  43.     } 
  44.     return 0;
  45. }
  46.  
  47.  
  48. void ThreadProc(void *param)
  49. {
  50.  
  51.     char *program = "c:\\WINDOWS\\notepad.exe";
  52.     spawnl(P_WAIT,program,program,NULL);
  53. }
Feb 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1814
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a TabControl to my form and placed a
4
6901
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. Instead, I created a managed C++ DLL (OneBoxAPI.dll) that wraps the desired API calls in a manner which is easy to call from C#. This way I can use the header files that are part of the API for all the defines and structs. I am having a problem...
3
4439
by: Binary | last post by:
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O Hi I'm in the process of narrowing down a problem, and I have reduced the code involved to the following If someone could do the following and verify what I am seeing (and offer any insight!), I would appreciate it Simply create a new "Win32 Console Project" in VC++ .NET 2003. On the "Application Settings" page, check the "Empty project" box. Click "Finish" Add a...
2
2862
by: Boris Fortes | last post by:
I need to unhook event receiver as result of native C++ event. It unhooks successfully, but __raise does not return and throws access violation. Visual Studio 2003 How to reproduce: Consol Win32 exe project
1
6776
by: Nasser | last post by:
Hello, I am coding a mathematical model with VC++. When I debug the code, I face with no erroe, but during executing, I face with below error "Unhandled exception at 0x0040c275 in Tar.exe: 0xC0000005: Access violation reading location 0x00000004". Could you tell me, how I can fix it? I have attached the code as follows:
0
2533
by: Bruce Pataki | last post by:
I am creating an MFC application with activeX document server support. The application runs perfectly fine when i run as a standalone application. But when i run the application in Internet explorer, it opens however opening a form from the top menubar, it gives an error "access violation reading location" having error code 0xC0000005 (Running in standalone mode does not give this error). I have used global pointers to the objects I...
2
9432
by: bhreddy | last post by:
Hi All, Can someone help me out how can I resolve the error "0xC0000005: Access violation reading location 0x513112f4"? Steps I followed... 1. I ran the application at DOS prompt 2. After some time my application got crashed and windows popped up a window asking for debug, send error report. 3. Clicking on Debug opens my workspace in .Net IDE.
10
1769
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, There is error message when executing my program, Unhandled exception at 0x00411a49 in test_entern.exe: 0xC0000005: Access violation reading location 0x00000002. It is very simple, does anyone know what is wrong with the program?
13
26667
by: ycinar | last post by:
A quick question: Why doesn't the following code catch the Access violation reading location exception? it crashes on line if ( xyz ) with an Access violation reading location exception. Is not catch supposed to catch it? Practically, it doesnt. try { if ( xyz ) // crashes here {
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.