|
Hi all,
I have a for loop parallelized with openMP. Inside I want to catch possible exceptions. My idea is that the caught exception should be a private variable, as it is possible that several exception occur parallel. But I cannot express this.
example:
#pragma omp parallel for default(none)
for ( int i = 0; i < 10; ++ i )
{
try
{
}
catch ( const std::exception& e )
{
e;
}
}
This yields to compiler error:
error C3052: 'e' : variable doesn't appear in a data-sharing clause under a default(none) clause
But I cannot mark the exception variable as private, as I is not known at that scope.
I can bypass the compiler error by changing the default sharing behaviour to shared, but I think this could lead to a runtime error, if two exceptions occur at the same time.
What is the correct way to deal with this?
Thanks in advance,
Joerg
|
|
|
|
|
I've got an application which has two dialogs, I use a deque and Direct2D in one dialog within a thread. Now, if I close the application via handling WM_CLOSE I have no problem but when I try and close it by clicking on 'Close Window' in the task bar or using Alt F4 I get a breakpoint triggered on
if (!HeapFree(select_heap(block), 0, block))
I know it's a long shot since I have given so little detail - but seeing as the difference seems to be in the way I close the app down I was hoping there might be a quick and easy fix for this.
Yours hopefully,
Ben
*Update since I posted in this it the next door forum, this morning, by mistake: I still get the same error if the thread (and hence the direct2d drawing) isn't running. Perhaps it is something to do with the way I set up the dialogs.
|
|
|
|
|
Isn't the WM_CLOSE message being sent whether you terminate the app via Task Manager or by using Alt+F4?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks for your reply!
I don't know, to be honest. The problem was occurring when I AltF4ed or clicked on Close Window but not when I clicked on my 'Exit' button. However, it looks like it was a corrupt memory problem I had with a member variable I'd assigned to the heap and was using to pass data between threads.
I've changed the communication to the following:
In the sending thread:
ControlDlg * pParent = (ControlDlg *) this->GetParent();
ColourAlphaEnvelope * s = new ColourAlphaEnvelope;
*s = m_ColourEnvelope;
pParent->PostMessage(CM_COLOURBOUNDS, reinterpret_cast<WPARAM>(s));
and in the recieving dialog I used
afx_msg LRESULT CRectArtDlg::OnCmColourbounds(WPARAM wParam, LPARAM lParam)
{
std::auto_ptr<ColourAlphaEnvelope> s(reinterpret_cast<ColourAlphaEnvelope*>(wParam));
m_colourEnvelope = *s;
return 0;
}
I bet there are dozens of better ways of doing this (not least since a quick Google reveals that auto_ptr is depracated) but I haven't had a crash and the compiler isn't telling me there is a memory leak.
|
|
|
|
|
Hi all,
i am developing client program using WSAAsyncselect() in Winsock2.
i have few queries regarding FD_WRITE.
i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server.
here is the pseudo.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SOMEOTHEREVENT:
break;
case WM_SOCKET:
switch (WSAGETSELECTEVENT(lParam))
{
case FD_WRITE:
break;
}
break;
}
return 0;
}
Thanks in advance.
|
|
|
|
|
Your application will receive an FD_WRITE event shortly after a connection is made. If your "write" operation receives a WSAEWOULDBLOCK result, your application will find out that sends are again possible when an FD_WRITE network event is recorded and the associated event object is set.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi David,
Thanks for your reply.
i am sorry, i couldn't get what you mean.
i understand that application will receive an FD_WRITE event shortly after a connection is made but there is no data to send at that time.
here is scenario i am trying for
1) connect to server
2) Connection established - FD_WRITE event is receive.
3) there is no data to send to server
4) some other event fired (not related to socket) -- data arrived, so store the data.
5) now data is available to send to server
in the above steps 4 and 5 will happen one after the another. how can i raise FD_Write event after the data is available (means step 4) ?
|
|
|
|
|
Vijjuuu. wrote: how can i raise FD_Write event after the data is available (means step 4) ? Why would you need to raise the FD_WRITE event? It is sent to your application to let it know that it can now send data to the socket.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks again David,
i understood that its lets application know that it can send data to the socket, but when there is no data to send ?
and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ?
i really appreciate your patience. Thanks.
|
|
|
|
|
Vijjuuu. wrote: ...but when there is no data to send ? Then don't send any.
Vijjuuu. wrote:
and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ? Did you read the documentation that goes with that event? Your application gets the initial FD_WRITE event which means it can start sending data to the socket. In the event that whatever "send" function you are using returns WSAEWOULDBLOCK , you would then have to wait for the next FD_WRITE event to resume sending data to the socket.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
As I understand it, the FD_WRITE message means you have a
connection and room in the output buffer to accept data.
After you get FD_WRITE, use send() to send data
when you have it.
modified 29-Jun-16 2:58am.
|
|
|
|
|
when i am using wmi functions "SELECT * FROM Win32_Processor", can i somehow get dll files from which is that information loaded?
|
|
|
|
|
|
Hi,
is it possible to print class members, like in Visual Studio in the "Immediate Window", when i write a class name there is an output with all members/variables in the window?
Is there an API for this?
Thanks for help
bosfan
|
|
|
|
|
In the debugger or as a simple output (printf/cout) ?
I'd rather be phishing!
|
|
|
|
|
Are you wanting reflection, like Java has?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello,
sorry to all because its late answer, yes reflections should be the solution.
Thanks
|
|
|
|
|
Such a thing does not exist, at least not directly, in C++.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Nope, you have to develop it yourself.
|
|
|
|
|
Hi,
sorry ,i'm little late, thanks for answer.
regards
|
|
|
|
|
|
In C++ this concept are overloading and overriding
Can i use this concept in C?
modified 16-Jun-16 10:40am.
|
|
|
|
|
What would the purpose be?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Yes you can but if you want to do it statically it has to be done via compiler directives and smart macros and it's used by embedded programmers in some specific situations. It is not something we encourage to use like the C++ feature but there are times it is the only way to achieve what is needed.
It has been improved and is portable and easy if your compiler accepts the C11 standard word "_Generic".
Here is a reasonable link on it
Rob's Programming Blog: C11 - Generic Selections[^]
You can see the general form of the macro which provides the overloading
#define acos(X) _Generic((X), \
long double complex: cacosl, \
double complex: cacos, \
float complex: cacosf, \
long double: acosl, \
float: acosf, \
default: acos \
)(X)
As the C community is still one of the larger programming languages the standard has been altered over time. In time order the main standards are C87, C90, C99, C11. Microsoft and Visual Studio has been one of the slowest compilers to include the new standards. Visual studio 2013 was the first version to cover most of C99 but it has been available in GCC and many micro-controller C compilers for many years.
In vino veritas
modified 16-Jun-16 12:55pm.
|
|
|
|