|
There is a global block accessible to all the threads
This is one of the fields
I going to double check that
The handle has the value initialized by CreateMutex later in tonite
|
|
|
|
|
Since it's a different thread... also check that the thread going to the wait state isn't waiting on a handle that hasn't been created yet.
|
|
|
|
|
You do realize you don't pass the handle around between threads right?
Read carefully
Two or more processes can call CreateMutex to create the same named mutex. The first process actually creates the mutex, and subsequent processes open a handle to the existing mutex. This enables multiple processes to get handles of the same mutex, while relieving the user of the responsibility of ensuring that the creating process is started first. When using this technique, you should set the bInitialOwner flag to FALSE; otherwise, it can be difficult to be certain which process has initial ownership.
If you go the other way and guarantee the inital thread opens it first you need to set the bInitialOwner flag and do a release. So your other choice.
The creating thread can use the bInitialOwner flag to request immediate ownership of the mutex. Otherwise, a thread must use one of the wait functions to request ownership. When the mutex's state is signaled, one waiting thread is granted ownership, the mutex's state changes to nonsignaled, and the wait function returns. Only one thread can own a mutex at any given time. The owning thread uses the ReleaseMutex function to release its ownership.
You seem to get getting confused between the two modes from what I am reading. You need to make a choice (a) or (b).
So I think you are getting this error because you are using the named technique without a name.
If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.
In vino veritas
modified 10-Nov-16 14:53pm.
|
|
|
|
|
I am modifying the Hercules mainframe emulator code
I have created a child
Process a Windows MFC
Program
Basically the data shared between all of the threads is stored in a DLL named sysblk
Thanks
|
|
|
|
|
Hi All,
We are trying to upgrade 32 bit MFC application to 64 bit application. In this process we are getting the
Debug Assertion Failed! error when the synchronization function WaitForMultipleObjectsEx() is called as
dwWaitResult=::WaitForMultipleObjectsEx(dwNumWaits,hWaits,FALSE,dwTimeout,TRUE);
where dwNumWaits values is 2, dwTimeout is INFINITE and hWaits is an array of 32 handles, in which only the first 2 handles are initialized.
This is perfectly worked with 32 bit application, but when we are testing the application in 64 bit, getting the above error.
Please let me know how we can resolve it.
Thanks,
Lakshmi Chowdam.
|
|
|
|
|
Member 12335695 wrote: Please let me know how we can resolve it. Step 1 is to use your debugger to trap the assertion and find out why it is occurring.
|
|
|
|
|
Hi,
Member 12335695 wrote: hWaits is an array of 32 handles
That is a alot of synchronization objects for a single thread. Please perform an audit/review on your code and check to see if your application is using greater than MAXIMUM_WAIT_OBJECTS which is probably defined as 64 on your operating system. Exceeding this number will cause failures at run-time that the compiler does not catch.
You might want to ask your engineers to design a better architecture that does not require single threads to wait on such a large number of handles.
Also please paste the entire contents of the "Debug Assertion Failed!" error message so we can further assist.
Best Wishes,
-David Delaune
modified 10-Nov-16 10:38am.
|
|
|
|
|
Please find the contents of the "Debug Assertion Failed!" error message as:
Debug Assertion Failed!
Program: C:\Windows\system32\mfc120ud.dll
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\barstat.cpp
Line: 99
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winfrm.cpp(1628) : AppMsg - Warning: no message line prompt for ID 0xE001.
Even though I restricted the synchronization objects to 2 only, then also I am getting the above same error.
Please let me know if you need more information on this?
|
|
|
|
|
And also, the creating events are:
hInterruptEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
hTDEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
hWaits[0]=hInterruptEvent;
hWaits[1]=hTDEvent;
Thanks,
Lakshmi Chowdam.
|
|
|
|
|
Member 12335695 wrote: Program: C:\Windows\system32\mfc120ud.dll
File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\barstat.cpp
Line: 99
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winfrm.cpp(1628) : AppMsg - Warning: no message line prompt for ID 0xE001.
This means that your status bar is missing an ATL/MFC resource string for the ATL_IDS_IDLEMESSAGE.
Add this to your .RC resource file:
STRINGTABLE
BEGIN
ATL_IDS_IDLEMESSAGE "Ready"
END
You may be missing other resource strings.
Best Wishes,
-David Delaune
|
|
|
|
|
Look at the call stack to see what the assertion was checking, that should give you clues as to where the actual problem may be. Are you using the same exact MFC version (other than 32v64bit) on both compilations?
|
|
|
|
|
I developed an exe,which would exports some pure C APIs for plugin dlls.
the code for the main exe is something like bellow:
class CA{};
class CB{};
class CC{};
class CCore
{
private:
CA* m_pCA;
CB* m_pCB;
CC* m_pCC;
};
void main()
{
CCore* pCore = new CCore;
while(true)
{
pCore->DoSomething();
}
delete pCore;
}
the code for a plugin is something like this
class CTestPlugin : public IPlugin
{
public:
virtual void Init()
{
}
virtual void UnInit()
{
}
};
I do not want to expose the pCore pointer or any other pointers from main exe to any plugin. so I need pure c style apis.
any ideas?thank you.
modified 10-Nov-16 2:40am.
|
|
|
|
|
|
Just hold make an internal array of PCore pointers and pass them out an Index number ... call it a handle ... I guess a HPCORE.
So they hold onto an index number and when they call a function the pass in the index number and you grab back the PCore pointer out of your array.
That is what all the HANDLES are in Windows, they have a number it tells them nothing about what happens internally it just a index to a internal pointer that never comes out. So you code becomes more like Windows API and they can have multiple HPCore handles.
void main()
{
HPCORE hPCore = CreateNewPCore();
while(true){
PCoreDoSomething(hPCore);
}
DestroyPCore(hPCore);
}
EDIT: Actually I am being slow do what windows does exactly pass back a pointer to the position in the internal array rather than the index as the handle. First saves having to use the number to traverse the array to get the pointer (so much much faster). Second you can test the handle being valid if you need because it must lie between PCoreArray[0] ... PCoreArray[Last] of your internal PCore pointer array. It's index position in the array which you only need to know when you dispose to empty the slot is straight forward
Handle Index = (Handle - &PCoreArray[0])/sizeof(Pointer).
So a handle is a PCore** .. that is a pointer to a pointer to a PCore but I would just typedef it as size_t and internally typecast it because you can check it via the above. So ...
typedef size_t HPCORE;
In vino veritas
modified 10-Nov-16 21:33pm.
|
|
|
|
|
thank you all very much!!!
|
|
|
|
|
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules:
A. If the average score is 90% or more, the grade is A.
B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B.
and it continues...
The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results.
This is what I have so far but it will not run for me. I am not allowed to use global declarations.
#include <stdio.h>
int main (void)
{
int score1, score2, score3;
char grade;
int temp = 0;
printf("Enter the test score (0-100): ");
scanf ("%d", &score1);
printf("Enter the test score (0-100): ");
scanf ("%d", &score2);
printf("Enter the test score (0-100): ");
scanf ("%d", &score3);
printf("The grade is: %c\n", score1, score2, score3);
return 0;
}
int temp = 0;
{
temp = (score1+score2+score3)/3;
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C';
else
if (score >= 60)
grade = 'D';
else
grade = 'F';
char grade;
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C';
else
if (score >= 60)
grade = 'D';
else
grade = 'F';
return grade;
}
help please
|
|
|
|
|
You need to hit the books or web lessons on C again. Your 3 statement inputs look good ... sorry that is it
Your printf statement is garbage hit the web or books and look up the words "formatted output of printf" and look at what %c means. However you have done absolutely nothing with the inputs to even think about calling that.
What we are saying is you need to call a function between the last input and trying to print anything ... so
scanf ("%d", &score3);
printf("The grade is: %c\n", score1, score2, score3);
You even have the text that boldly says "// Function declarations" only you don't have anything there you just drop straight into main. Let me guess that was a hint in the template they gave you and you don't even get what it means?
ScoreToGrade which was obviously was intended as your function is hanging out way down the bottom. You need to either forward declare it where you boldly declare you are going to have "// Function declatations" or move it up to there. So it's a cut and paste job or look up how to forward declare a prototype.
Final problem
int temp = 0;
It says it is local it is in fact a global variable ... you need to work out why.
In vino veritas
|
|
|
|
|
Hi Friends,
I have been asked in interviews like "How explicit , volatile and mutable keywords works INTERNALLY in C++ ?" Please let me know.
Rgeards,
Amrit
|
|
|
|
|
|
Explicit and volatile you need to know, if you are seen using mutable in C++ we put you up against the wall and shoot
There are a couple of places you need volatile the two main ones are in multitasking code and interfacing to physical hardware. What volatile tells the compiler the result at that address can change between uses of it ... so it stops the optimizer assuming the value hasn't changed between uses of that address.
Imagine the situation you have code that reads the port of a timer at an address. Then you do some other stuff not touching the port address and then you go an read the port again. Now if you are dealing with memory the two reads will have the same value as the code between the two reads didn't touch the port. So an optimizer might well conclude it can remove the second read and just hold the first read value. Only in reality the timer values ticks because it's hardware and so we need the second read to occur it can't be optimized. The same situation occurs in multitasking, memory that our own code didn't touch can change. So volatile is about making sure the optimizer doesn't shortcut stuff assuming just because the code hasn't touched it, that it hasn't changed. So any variable marked with volatile will have any action on that variable not subject to optimization.
Explicit is when you want the compiler to stop being smart and convert types for you and pretending it's GWBASIC
It used to happen mostly on class/object code that a constructor for example would take a string as a parameter. If you gave it an integer it would automatically know to convert the integer to a string, which is pretty cool sometimes. Other times it leads to a complete and utter bug because you didn't allow for it. So if you tell the compiler you want explicit it turns off the GWBASIC parser and stops the conversion it will throw an error instead.
Mutable is one you will rarely if ever need and if you do need it most of us will argue your code is badly organized or you are super lazy and dangerous. The better name for it would be cached or stencil playtime. So you have a constant or someone passes you in a constant, but you just want to change it I mean string "Drive A" is so close to "Drive B". You declare it mutable you can now play around with the constant it wont change the real constant just your local play copy. It's not something to encourage in that usage. The only real valid use of the directive is when you really are dealing with a real cache such as synchronization objects like mutexes & semaphores. It really exist solely for those unique situations and really shouldn't be abused.
Now I am being flippant so you actually take time to go read up on them properly but that is the basics.
In vino veritas
|
|
|
|
|
i have game application .exe and if someone target my .exe got crash (ddos attack)
i need to create dll file or application to can block or stop high traffic for port
any suggestion ?!
|
|
|
|
|
|
It's not something you deal with at your point as your internet provider will still attempt to deliver the messages to your single IP. So eventually your feed gets overloaded even if you are just reading the packet from the network card and disposing of them because you realize they are junk.
The easiest solution is sign up to a Content Delivery Network, they stop the data ever getting to your server. If you search that term plus your country I am sure you will find some companies to talk to and look at pricing for.
The other option you may want to consider if this is commercial is hiring virtual servers from a VM server farm. They can configure the Virtual server to whatever O/S you need and you run your program on their server. They usually do all the DDOS prevention stuff as part of the deal as they have that stuff already because they have hundreds if not thousands of servers.
In vino veritas
modified 6-Nov-16 11:08am.
|
|
|
|
|
thanks a lot bro .. i think that will be so expensive for me .. because i am Arabian .. with dollars will be higher per month ... i will try software can control traffic and filtering as i can .. if you have suggestion for software that will be awesome ... thanks again
|
|
|
|
|
I just started to learn C++, coming from a C# and Java background.
I like to use interfaces in my code. In C++ though they do not exist so instead I make structs with pure virtual methods. I'm interested in opinions on different conventions used.
My questions are:
1) From what I understand there is no difference between struct and class besides the default accessor, but it is common place to see struct being used when the class is of a smaller size. Therefore I decided as a convention to use struct when writing interfaces since the way struct is viewed by programmers more closely resembles an interface. Are there any other conventions on this issue or is my convention bad or could cause confusion in any way?
2) Since an interface only has pure virtual and provides no implementation (most of the times, default methods are now a thing in Java) I thought it would be logical to only make a header file for it, instead of making both a .cpp and a .h file. Since a .cpp file is supposed to have the implementation and the .h file is supposed to have the method prototypes. Again, are there any other conventions on this issue or is my convention bad or could cause confusion in any way?
Example:
ISayHello.h
struct IRender
{
virtual void render() = 0;
}
ImplementationExample.cpp
class Sprite : public IRender
{
public:
void render() override
{
}
}
What I have tried:
NOTE: My intention is to get the opinion of those with more experience on how my pattern works, if it has problems, and if there is any other convention on issue that my convention is addressing. If you think the question is off topic I would appreciate if you could redirect me to a better place to ask my question. This question for example was marked as off topic on the Code Review Stack Exchange, though in my opinion asking for review on a pattern you in your code is not off topic.
|
|
|
|