|
I still don't know how to achieve this.
Any help is very appreciated!
Thanks in advance, Sebastian
|
|
|
|
|
I would like to be able to terminate a worker thread(for example, if it is in an endless loop)in such a way that the worker thread can clean up before terminating. I've thought that one way might be to cause an exception that the worker thread can catch. Is there a way for one thread to force an exception in another thread in the same process?
|
|
|
|
|
See here.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thanks for the informtaion. Unfortunately, the programs that the worker threads are running are not mine, so I cannot make any modifications to them to check for thread status.
I'm wondering if it is possible to pause the worker thread, change the EIP register to point to my own code, and then resume the thread so that an exception is raised. I would like to do something that is reasonably standard so that I don't have to rewrite the code for 64 bit processors.
|
|
|
|
|
You shouldn't have to make any changes to the program that the secondary thread is spawning. The termination of a thread is a cooperative effort between the primary and secondary threads. If the secondary thread, in turn, needs to notify the program that it spawned, it can do so via SendMessage() or PostMessage() .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi,
In a class I receive a pointer to a structure, I want to find out how many variables, has this structure and also what are their types or sizes!
Somehow silly, I know. just curious to know if it is possible.
I receive the pointer as (void*), and need to place it's data in to 'a part of memory'with the same size as the structure!! then use each data separately!! ;P
example:
struct x {
int a;
int b;
}
<code>
struct x aVar;
read (&aVar);
...
...
</code>
void read(void* st)
{
int nVal_cnt = ? ;
int val1_size = ? ;
}
//This is not a signature
while (I'm_alive) {
printf("I Love Programming");
}
-- modified at 6:15 Saturday 25th February, 2006
|
|
|
|
|
i think you didn't really get the point with structures.
a struct is only a scheme of how will be filled the memory of an instance of this type...
a struct don't have a variable number of variables nor types...
they are fixed when you define this type.
and note that a speak of type !!
if you define this :
struct T {
int a;
int b;
};
then T is not a variable, but a type !!!!!!
after that only, you can use it tyo create variables :
T var;
var.a = 2;
var.b = 5;
do you get me ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.24][3.0 soon...]
|
|
|
|
|
Modified
I think I was not able to say what I want correctly.
I understand the diffrence between a type and a variable.
I want to find out some information from a variable defined from a structure.
In my example I defined a type x, now consider the variable 'struct x aVar' , now if I receive a pointer to this variable(&aVar ), how can I find out some information about it? number of it's elements.
Is it clear or I failed again?;P
P.s.
In my old example: "void read(void* st) " is a function declaration receiving a pointer to a variable of the type struct x.
//This is not a signature
while (I'm_alive) {
printf("I Love Programming");
}
-- modified at 11:07 Friday 24th February, 2006
|
|
|
|
|
Hamed Mosavi wrote: Is it clear or I failed again?
not sure to understand yet, but i'll give it a try again
do you mean that "how to access to the members of a struct variable when you have a pointer on it" ?
if yes, you have 2 way :
as when you use the variable directly (no pointer), you use the . operator, you can do the same there :
struct T& var;
(*var).a = 5;
(*var).b = 12;
the other way is to use the -> operator :
struct T& var;
var->a = 5;
var->b = 12;
now, if i'm still wrong, tell me again
TOXCCT >>> GEII power [toxcct][VisualCalc 2.24][3.0 soon...]
|
|
|
|
|
you don't understand his question.
he wants to know if a function only receives a void* he can do a memcopy ( or something similar ) to a known structure.
for example
void f( void* data )
{
int iSize = SizeOf(data);
int iCountVar = NumberOfMembers( data );
}
all this without knowing what data is.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Mr. Toxcct:
Thankyou very much for your attention.
But I'm not that much begginer
I am writing a class, it has a function that receives a pointer to an unknown structure. The class does not know what type of a structure, with how many data elements will be received.
I was thinking that if I have a pointer to a structure in the memory, and type or size of the first element, using sizeof I'll be able to get next elements.
if for example size of the first element = 2Bytes and st is the pointer, sizeof(st+2) will give me the second element size. I'll read from st+2 as much as this size, and I have the next variable.
I then thought that C, C++ compiler will save information about every variable in memory, so I might find an easier way to it.
now, Am I still failing? please say no!!
Thank you very much again
//This is not a signature
while (I'm_alive) {
printf("I Love Programming");
}
|
|
|
|
|
oh
no, actually, void* is simply an address, and the compiler don't know what is stored there (because it can change at any time at runtime...
but aren't template a bit what you're looking for ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.24][3.0 soon...]
|
|
|
|
|
I never read templates seriously.
But, I think not!
I am going to save this structure to a file!!
Modefied
In fact you're right about void*, but think about the fact that this pointer actually refers to a place in the memory that compiler know it's identity!
I think this is similar to 'explicit linking'(if I'm right about the english term)! when compiler doesn't know about it at compile time, but does so at run time.
End Modefied
any way thank you very much.
It was your kindness to pay attention.
//This is not a signature
while (I'm_alive) {
printf("I Love Programming");
}
-- modified at 12:01 Friday 24th February, 2006
|
|
|
|
|
AFAIK, you can't, when receiving a void* you are just receiving a memory address; nothing about the structure of the memory at that point.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Hamed Mosavi wrote: I receive the pointer as (void*), and need to place it's data in to 'a part of memory'with the same size as the structure!! then use each data separately!
what about casting that Void pointer to the Structure.. i.e. something like this :-
void read(void* st)
{
x *objX=(x*)st;
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
Cast to what?!
I don't know any thing of the pointer I get! Even if I know the name, both the size and name of the data elements of the structure are unknown.
Thank you anyway, and excuse me for replying so late.
//This is not a signature
while (I'm_alive) {
printf("I Love Programming");
}
|
|
|
|
|
Hello All,
Pls help me.
How to use event NM_RETURN in the CListCtrl It's not response.
Thank you
|
|
|
|
|
The NM_RETURN notificaton is sent in the form of a WM_NOTIFY message.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
Not sure I understand you exactly, but if you are having trouble getting that notification mesage, remember that NM_* notifications are sent via WM_NOTIFY (Win32's WM_COMMAND notification message), so you need to be catching WM_NOTIFY messages being sent from the control.
In MFC you can use the ON_NOTIFY message map macro - look it up in MSDN for examples.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi guys,
We are using IO Completion Ports in a server application. But I'm not sure exactly when a socket is closed. This is what I mean:
BOOL GetQueuedCompletionStatus(
HANDLE CompletionPort,
LPDWORD lpNumberOfBytes,
PULONG_PTR lpCompletionKey,
LPOVERLAPPED* lpOverlapped,
DWORD dwMilliseconds
);
So according to the MSDN, a socket is closed when
lpOverlapped is not NULL, lpNumberOfBytes == 0 and the value returned by the function GetQueuedCompletionStatus is ERROR_SUCCESS /0/.
But I have cases when GetQueuedCompletionStatus returns 1, lpOverlapped and lpNumberOfBytes is 0 -- does it mean the socket is closed on the other side? Because if I assume that, the other side is notifying that the server side closed the connection.
Someone with any experience with that? Please, help!
Does someone know about any problems with hyper-threading and IOCP?
Cause when I'm running the server application on a dual processor machine with hyper-threading the number of dropped connections increases.
Thanks,
Yani
|
|
|
|
|
Well, I have only used IOCPs themselves, and not associating them directly with another HANDLE-based object, so take what I write at the bottom with a grain of salt... However, about HT processors, one of the things that many people do not understand about HT processors is that they are not the same as a real multiple-CPU system or a multi-core processor.
HTs share an execution engine, so technically, they will compete with each other for an on-die resource (IIRC, they can decode and retire instructions at the same time, but they cannot dispatch them). This contention may be causing unexpected things to happen with your code. (You can find HT documentation that discusses the architecture and differences on Intel's web site.)
Also, note that the documentation you have for GetQueuedCompletionStatus(...) may be incorrect - older docs mentioned that in the case of SOCKET closure, the function returns ERROR_SUCCESS , but the function returns a BOOL value, not a DWORD . I think that it returns TRUE , sets the variable pointed to by lpNumberOfBytes to zero, and GetLastError() will return ERROR_SUCCESS .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks, James
but the problems is the when I simulate a dropped connection by killing the process of running our client application
GetQueuedCompletionStatus(...) reruns 0, and GetLastError() return 0 too.
It's pretty confusing because I read the msdn docs and
ERROR_SUCCESS - 0 The operation completed successfully.
If the function /GetQueuedCompletionStatus/ dequeues a completion packet for a successful I/O operation from the completion port, the return value is nonzero.
So I still do not know what to do when GetQueuedCompletionStatus 1 with 0 bytes read....
Thanks,
Yani
|
|
|
|
|
Sorry - no further ideas... Except that if you never send an empty packet over, you might be able to use an read bytes value of zero to indicate closure of the socket...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
thanks
I had same problem 
|
|
|
|