Recently I had posted a query about intermittent problems with a
C++/Interop scheme (unmanaged C DLL wrapped in unmanaged C++,
wrapped in managed C++, all accessed by C#). The system works fine
when unstressed, but fails under stress.
Well...I just noticed short mention in Prosise's book, of all places,
re threading. He indicated that the behavior of unmanaged code within
managed threads is not predictable. I had thought that the organized
internal alloc/shutdown within the embedded unmanaged classes was
good enough to keep things in line. Maybe not.
Do I need to take all the unmanaged code out to an UNmanaged thread?
(Yechh!) Is this documented anywhere?
_B 15 1385
I wouldn't think so. What is the context of Prosise' statement? I'm sure it
won't infringe copywrites if you post a replication/summation
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------
"_BNC" <_B**@noemail.o rg> wrote in message
news:in******** *************** *********@4ax.c om... Recently I had posted a query about intermittent problems with a C++/Interop scheme (unmanaged C DLL wrapped in unmanaged C++, wrapped in managed C++, all accessed by C#). The system works fine when unstressed, but fails under stress.
Well...I just noticed short mention in Prosise's book, of all places, re threading. He indicated that the behavior of unmanaged code within managed threads is not predictable. I had thought that the organized internal alloc/shutdown within the embedded unmanaged classes was good enough to keep things in line. Maybe not.
Do I need to take all the unmanaged code out to an UNmanaged thread? (Yechh!) Is this documented anywhere?
_B
On Mon, 31 Jan 2005 12:05:54 -0400, "Alvin Bruney [MVP]" <vapor at
steaming post office> wrote: I wouldn't think so. What is the context of Prosise' statement? I'm sure it won't infringe copywrites if you post a replication/summation
I doubt that Jeff would mind. p668, under 'terminating threads':
"Abort throws a ThreadAbortExce ption in the targeted thread, causing the
thread to edn. The thread might not end immediately; in fact, it's not
guaranteed to end at all. If the thread has called out to unmanaged code,
for example, and hasn't yet returned, it doesn't terminate until it begins
executing managed code again. ..."
I hadn't expected much on unmanaged code in Jeff's book, but I still
haven't got a solid grip on what is going on in mgd/unmgd, so in my spare
time I've been combing through all my books and references to unmanaged
code.
The scenario above could happen, I think, as the original code was
designed to loop til it got a result-- or until its thread was aborted.
It hadn't occurred to me that the *managed thread* can no longer control
some of the code inside the thread. The symptoms don't all match up,
but that's par for this program.
I didn't read your old post about your problem but
I think a good design is to avoid methods like Thread.Abort
or / and TerminateThread since they always cause you
problem in the "long" run. I think a more controlled signal
is needed when you whish to shut down your thread.
You could use an w32 event object for this notification,
it is possible to access these from managed code as well
// daniel
"_BNC" wrote: On Mon, 31 Jan 2005 12:05:54 -0400, "Alvin Bruney [MVP]" <vapor at steaming post office> wrote:
I wouldn't think so. What is the context of Prosise' statement? I'm sure it won't infringe copywrites if you post a replication/summation
I doubt that Jeff would mind. p668, under 'terminating threads':
"Abort throws a ThreadAbortExce ption in the targeted thread, causing the thread to edn. The thread might not end immediately; in fact, it's not guaranteed to end at all. If the thread has called out to unmanaged code, for example, and hasn't yet returned, it doesn't terminate until it begins executing managed code again. ..."
I hadn't expected much on unmanaged code in Jeff's book, but I still haven't got a solid grip on what is going on in mgd/unmgd, so in my spare time I've been combing through all my books and references to unmanaged code.
The scenario above could happen, I think, as the original code was designed to loop til it got a result-- or until its thread was aborted. It hadn't occurred to me that the *managed thread* can no longer control some of the code inside the thread. The symptoms don't all match up, but that's par for this program.
I'm wondering out loud if the CLR team cannot provide a cleaner way to
terminate a thread that would be internally implemented?
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------
"Daniel Petersson, Cefalo" <da************ **@cefalo.se.do notspam> wrote in
message news:D0******** *************** ***********@mic rosoft.com... I didn't read your old post about your problem but I think a good design is to avoid methods like Thread.Abort or / and TerminateThread since they always cause you problem in the "long" run. I think a more controlled signal is needed when you whish to shut down your thread. You could use an w32 event object for this notification, it is possible to access these from managed code as well
// daniel
"_BNC" wrote:
On Mon, 31 Jan 2005 12:05:54 -0400, "Alvin Bruney [MVP]" <vapor at steaming post office> wrote:
>I wouldn't think so. What is the context of Prosise' statement? I'm sure >it >won't infringe copywrites if you post a replication/summation
I doubt that Jeff would mind. p668, under 'terminating threads':
"Abort throws a ThreadAbortExce ption in the targeted thread, causing the thread to edn. The thread might not end immediately; in fact, it's not guaranteed to end at all. If the thread has called out to unmanaged code, for example, and hasn't yet returned, it doesn't terminate until it begins executing managed code again. ..."
I hadn't expected much on unmanaged code in Jeff's book, but I still haven't got a solid grip on what is going on in mgd/unmgd, so in my spare time I've been combing through all my books and references to unmanaged code.
The scenario above could happen, I think, as the original code was designed to loop til it got a result-- or until its thread was aborted. It hadn't occurred to me that the *managed thread* can no longer control some of the code inside the thread. The symptoms don't all match up, but that's par for this program.
The CLR depends on the OS service offered to terminate a (OS) thread, and
it's that service (TerminateThrea d) which is "dangerous by nature".
Willy.
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:uE******** ******@TK2MSFTN GP15.phx.gbl... I'm wondering out loud if the CLR team cannot provide a cleaner way to terminate a thread that would be internally implemented?
-- Regards, Alvin Bruney [MVP ASP.NET]
[Shameless Author plug] The Microsoft Office Web Components Black Book with .NET Now Available @ http://tinyurl.com/27cok ----------------------------------------------------------
"Daniel Petersson, Cefalo" <da************ **@cefalo.se.do notspam> wrote in message news:D0******** *************** ***********@mic rosoft.com...I didn't read your old post about your problem but I think a good design is to avoid methods like Thread.Abort or / and TerminateThread since they always cause you problem in the "long" run. I think a more controlled signal is needed when you whish to shut down your thread. You could use an w32 event object for this notification, it is possible to access these from managed code as well
// daniel
"_BNC" wrote:
On Mon, 31 Jan 2005 12:05:54 -0400, "Alvin Bruney [MVP]" <vapor at steaming post office> wrote:
>I wouldn't think so. What is the context of Prosise' statement? I'm >sure it >won't infringe copywrites if you post a replication/summation
I doubt that Jeff would mind. p668, under 'terminating threads':
"Abort throws a ThreadAbortExce ption in the targeted thread, causing the thread to edn. The thread might not end immediately; in fact, it's not guaranteed to end at all. If the thread has called out to unmanaged code, for example, and hasn't yet returned, it doesn't terminate until it begins executing managed code again. ..."
I hadn't expected much on unmanaged code in Jeff's book, but I still haven't got a solid grip on what is going on in mgd/unmgd, so in my spare time I've been combing through all my books and references to unmanaged code.
The scenario above could happen, I think, as the original code was designed to loop til it got a result-- or until its thread was aborted. It hadn't occurred to me that the *managed thread* can no longer control some of the code inside the thread. The symptoms don't all match up, but that's par for this program.
You simply have to call return from the thread method to terminate a thread
the clean way.
"Alvin Bruney [MVP]" <vapor at steaming post office> schrieb im Newsbeitrag
news:uE******** ******@TK2MSFTN GP15.phx.gbl... I'm wondering out loud if the CLR team cannot provide a cleaner way to terminate a thread that would be internally implemented?
-- Regards, Alvin Bruney [MVP ASP.NET]
[Shameless Author plug] The Microsoft Office Web Components Black Book with .NET Now Available @ http://tinyurl.com/27cok ----------------------------------------------------------
"Daniel Petersson, Cefalo" <da************ **@cefalo.se.do notspam> wrote in message news:D0******** *************** ***********@mic rosoft.com...I didn't read your old post about your problem but I think a good design is to avoid methods like Thread.Abort or / and TerminateThread since they always cause you problem in the "long" run. I think a more controlled signal is needed when you whish to shut down your thread. You could use an w32 event object for this notification, it is possible to access these from managed code as well
// daniel
"_BNC" wrote:
On Mon, 31 Jan 2005 12:05:54 -0400, "Alvin Bruney [MVP]" <vapor at steaming post office> wrote:
>I wouldn't think so. What is the context of Prosise' statement? I'm
sure >it >won't infringe copywrites if you post a replication/summation
I doubt that Jeff would mind. p668, under 'terminating threads':
"Abort throws a ThreadAbortExce ption in the targeted thread, causing
the thread to edn. The thread might not end immediately; in fact, it's not guaranteed to end at all. If the thread has called out to unmanaged code, for example, and hasn't yet returned, it doesn't terminate until it begins executing managed code again. ..."
I hadn't expected much on unmanaged code in Jeff's book, but I still haven't got a solid grip on what is going on in mgd/unmgd, so in my
spare time I've been combing through all my books and references to unmanaged code.
The scenario above could happen, I think, as the original code was designed to loop til it got a result-- or until its thread was aborted. It hadn't occurred to me that the *managed thread* can no longer
control some of the code inside the thread. The symptoms don't all match up, but that's par for this program.
"cody" <de********@gmx .de> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl... You simply have to call return from the thread method to terminate a thread the clean way.
And what if the thread is blocked or is in an infinite loop?
There is nothing wrong with Thread.Abort as long as you call it
synchronously. When called asynchronously you have to terminate the process
when done or unload the application domain if not running in the primary
domain.
Willy.
What do you mean with "terminate the process"? Why should I have to
terminate the whole application if I only want to terminate one thread? And
if a terminate the last thread in an application shouldn't the process be
terminated automatically by the system?
"Willy Denoyette [MVP]" <wi************ *@pandora.be> schrieb im Newsbeitrag
news:OO******** ******@tk2msftn gp13.phx.gbl...
"cody" <de********@gmx .de> wrote in message news:u0******** ******@TK2MSFTN GP10.phx.gbl... You simply have to call return from the thread method to terminate a thread the clean way.
And what if the thread is blocked or is in an infinite loop? There is nothing wrong with Thread.Abort as long as you call it synchronously. When called asynchronously you have to terminate the process when done or unload the application domain if not running in the primary domain.
Willy.
If you happen to abort a thread asynchronously, that means an exception can
bet thrown at any moment during program execution, you possibly have
corrupted the application state.
Consider following thread procedure
void SomeProc()
{
lock(myLock)
{
}
}
, when the exception is thrown during the execution of the finalize clause
(compiler generated from lock()), chances are that the lock is not released.
If it happens that you are executing unmanaged code during Abort, chances
are that locks held by your unmanaged code will not being released, buffers
not freed, semaphores not cleared etc.
If it happens during managed execution of global state initialization
(static's), you'll end with incorrectly initialized global state.
So, I think it's clear there is no other option then to exit the process or
throw away the application domain.
Not sure what you mean with:
terminate the last thread in an application shouldn't the process be terminated automatically by the system?
calling Thread.Abort on your current thread, is a synchronous Abort
(synchronous exception), and yes if it happens on the last managed thread in
the application, the CLR will shutdown the process.
Willy.
"cody" <de********@gmx .de> wrote in message
news:%2******** *********@TK2MS FTNGP10.phx.gbl ... What do you mean with "terminate the process"? Why should I have to terminate the whole application if I only want to terminate one thread? And if a terminate the last thread in an application shouldn't the process be terminated automatically by the system?
"Willy Denoyette [MVP]" <wi************ *@pandora.be> schrieb im Newsbeitrag news:OO******** ******@tk2msftn gp13.phx.gbl...
"cody" <de********@gmx .de> wrote in message news:u0******** ******@TK2MSFTN GP10.phx.gbl... You simply have to call return from the thread method to terminate a thread the clean way.
And what if the thread is blocked or is in an infinite loop? There is nothing wrong with Thread.Abort as long as you call it synchronously. When called asynchronously you have to terminate the process when done or unload the application domain if not running in the primary domain.
Willy.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: P Reddy |
last post by:
Hi All,
Greetings!!!
I have a question. Please respond....
I am trying to write a C# component that need to inherit some of the the
interfaces from unmanged code(VC).
I think one way to resolve this is to port unmanged interfaces and header
files in to manage C++ as Visual Studio allows porting and compiling all this
|
by: skg |
last post by:
I am passing the address of pointer like char** from managed extension and
getting the
its initialized value from a C library dll.
How can i free the memory from the code in Managed Extension ?
Here is a sample C function i am calling from managed extension.
C dll Code
==============
|
by: Greg Roberts |
last post by:
Hi
I was wondering if there are some issues with socket support in this
situation :
- Main program is unmanaged C/C++ which is using windows sockets for its
coms to other unmanaged programs
- The program includes some new C# managed components (via unmaged to
managed interfaces) which
internally are using .NET framework sockets for its coms (to another server
|
by: Dan |
last post by:
I'm trying to create and display a user control written in C# in one of our
legecy C++ apps.
Everything compiles and links fine and the managed control is being created
but there's no sign of it in the window. That is, I get no run-time errors. I
created test apps to bypass the complexities of the real classes I have to
deal with.
When I had no luck using the managed class directly through the gcroot
template I added the CWnd wrapper...
|
by: kilroytrout |
last post by:
When trying to use some unmanged C++ libs in a VS 2005 Release
Candidate Windows Forms (/clr) project, I found that any dynamic
initialization in the lib's global STL objects (perhaps other C++
objects as well) create an exception at startup. Has anyone seen this
or know a workaround?
For example create a simple /clr C++ console app:
#include "unmanaged.h"
| |
by: Maxwell |
last post by:
Hello,
Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project
where I have a managed class reference in a unmanaged class...simple
enough. To keep things short I am for the most part attempting to do
what is this article by Nish:
http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw
I have to hook up a unmanaged callback to a managed method using IJW
NOT P\Invoke. So I am employing this "Thunk" or "Bridge" class...
|
by: brian_harris |
last post by:
I have a string object that I need to convert into an unmanged char * to be
used by several unmnaged 3rd party functions.
I have tried to use: (Marshal::StringToHGlobalAuto (Profname))
This would get me an IntPtr value, but I could not find the correct way to
cast an IntPtr to an unmanged char *.
One example I tried was:
char *inifile;
inifile = static_cast <char*> (Marshal::StringToHGlobalAuto (Profname));
It gave following compile...
|
by: mschuck |
last post by:
Here is the scenario I'm trying to make work.
I've got 2 managed C++ classes, each of which wrappes an unmanaged C++
class, kind of like so:
__nogc class UnmanagedClassA
{
public:
void SetUnmanagedB( UnmangedClassB* val );
....
|
by: B. |
last post by:
my small project has two files, umg.cpp (unmanaged c++) and mged.cpp
(MC++), and unmanged code will call managed code. However, I cannot
debug from unmanged code into managed code. Can anyone help me to solve
the problem?
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |