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 - Dword_align:
-
test edi,11b ;U - destination dword aligned?
-
jnz short CopyLeadUp ;V - if we are not dword aligned already, align
-
-
shr ecx,2 ;U - shift down to dword count
-
and edx,11b ;V - trailing byte count
-
-
cmp ecx,8 ;U - test if small enough for unwind copy
-
jb short CopyUnwindUp ;V - if so, then jump
-
-
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
3 8058
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
sicarie 4,677
Recognized Expert Moderator Specialist
Well, thanks for posting anyway, please feel free to post again if you run into anything else.
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: -
#include <windows.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <stdio.h>
-
#include <conio.h>
-
#include <process.h>
-
-
// Secound Thread function
-
void ThreadProc(void *param);
-
-
-
// First thread
-
int main()
-
{
-
-
int n;
-
int i;
-
int val = 0;
-
HANDLE handle;
-
DWORD dwRetVal ;
-
-
printf("\t Thread Demo\n");
-
printf("Enter the number of threads : ");
-
scanf("%d",&n);
-
-
while (n>MAXIMUM_WAIT_OBJECTS)
-
{
-
printf("Enter the number of threads smaller than 64 : ");
-
scanf("%d",&n);
-
}
-
{
-
//HANDLE *pArrayInt= (HANDLE *)malloc (n);
-
HANDLE pArrayInt[MAXIMUM_WAIT_OBJECTS];
-
-
for(i=0;i<n;i++)
-
{
-
val = i+1;
-
handle = (HANDLE) _beginthread( ThreadProc,0,&val); // create thread
-
pArrayInt[i] = handle;
-
printf ("%d Handle \n",handle);
-
}
-
dwRetVal =WaitForMultipleObjects((DWORD)n,pArrayInt,TRUE,INFINITE);
-
}
-
return 0;
-
}
-
-
-
void ThreadProc(void *param)
-
{
-
-
char *program = "c:\\WINDOWS\\notepad.exe";
-
spawnl(P_WAIT,program,program,NULL);
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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...
|
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
|
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:
| |
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...
|
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.
|
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?
|
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
{
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |