Re: Console app freezes

From: Ilya Tumanov [MS] (ilyatum_at_online.microsoft.com)
Date: 12/20/04


Date: Mon, 20 Dec 2004 18:14:54 GMT

This behavior seem to be a result if excessive CPU load.
Do you have some tight loops anywhere? Say, waiting for something?
Do you know what your app will do in case more data is coming from serial
port(s) than can be processed?
Could it wait for available buffer in a loop without sleep() in it?
That would cause the "serial" thread to use 100% CPU, which would slow down
all other thread, which would slow down data processing, which would cause
"serial" thread to wait... and so on. As you remove incoming data, your app
would eventually process data and unlock itself.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
> Thread-Topic: Console app freezes
> thread-index: AcTmVRfikLPVHZaeRoiMCjHGM79gMA==
> X-WBNR-Posting-Host: 202.6.138.45
> From: "=?Utf-8?B?TWljaGFlbC0tSg==?=" <MichaelJ@discussions.microsoft.com>
> References: <2A88D523-2302-4891-943E-2170F347100A@microsoft.com>
<41c11d2a$1@news.microsoft.com>
<BE00D6F5-A077-47D8-9C4A-3528F9494CE9@microsoft.com>
<KNzYqk64EHA.3512@cpmsftngxa10.phx.gbl>
> Subject: Re: Console app freezes
> Date: Sun, 19 Dec 2004 21:31:02 -0800
> Lines: 204
> Message-ID: <728DC81F-04A6-43A7-BCE5-D4132D86CDF6@microsoft.com>
> MIME-Version: 1.0
> Content-Type: text/plain;
> charset="Utf-8"
> Content-Transfer-Encoding: 8bit
> X-Newsreader: Microsoft CDO for Windows 2000
> Content-Class: urn:content-classes:message
> Importance: normal
> Priority: normal
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:67211
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> Hi,
>
> I did more tests and have encountered a few strange behaviours. The test
> only involved port1 and port3. Each port processed serial input composed
of
> 40 packets/sec where each packet averaged around 30 bytes in size. In the
> background, i still have the same 3 timers working as well as the IP
stuff
> (refer to my first post regarding what my app does).
>
> Ok, when i deploy the app to my device in debug mode, it runs fine until
> some arbitrary point in time where the console just freezes (Console's
cursor
> stops flashing and system time stops). However, after waiting a while, I
> noticed that the cursor actually blinked to it’s opposite colour and
the time
> updated itself to the current time and then it “freezes” again. I
don’t think
> the app is actually “frozen”, it’s still running (in the background
somehow)
> but the IP networking stuff isn’t active. Then i decided to remove
port1's
> serial input and after some time, the app began to work properly again
(i.e.
> Console's cursor was flashing and the system time was working). I
reconnect
> port1's input, the app "freezes" again after a while. I remove port1's
input,
> and it works again, and so on.
>
> Does having 4 separate threads, each processing serial input, cause
problems
> in resource-contrained devices or is this still a race condition issue?
Any
> ideas as to why the behaviour i mentioned above happens? Thanks in
advance.
>
> Michael--J.
>
> ""Ilya Tumanov [MS]"" wrote:
>
> >
> > If something's corrupted, anything could happen.
> > May be, you have a loop you could never leave because another thread
> > messing with loop counter.
> > Or, may be, you have a classical deadlock. Whatever the reason, it is
> > fixable.
> >
> > Just carefully identify all shared objects and add locking if these
objects
> > are not thread safe.
> >
> > If you're using some sort of custom semaphores (not the lock
statement),
> > don't forget to unlock objects even if you have an exception.
> > You might use finally blocks to do so.
> >
> > Best regards,
> >
> > Ilya
> >
> > This posting is provided "AS IS" with no warranties, and confers no
rights.
> >
> > --------------------
> > > Thread-Topic: Console app freezes
> > > thread-index: AcTjYMfjNS4Xr4DlR9GS/Qlk1bulQw==
> > > X-WBNR-Posting-Host: 211.26.115.247
> > > From: "=?Utf-8?B?TWljaGFlbC0tSg==?="
<MichaelJ@discussions.microsoft.com>
> > > References: <2A88D523-2302-4891-943E-2170F347100A@microsoft.com>
> > <41c11d2a$1@news.microsoft.com>
> > > Subject: Re: Console app freezes
> > > Date: Thu, 16 Dec 2004 03:17:08 -0800
> > > Lines: 100
> > > Message-ID: <BE00D6F5-A077-47D8-9C4A-3528F9494CE9@microsoft.com>
> > > MIME-Version: 1.0
> > > Content-Type: text/plain;
> > > charset="Utf-8"
> > > Content-Transfer-Encoding: 7bit
> > > X-Newsreader: Microsoft CDO for Windows 2000
> > > Content-Class: urn:content-classes:message
> > > Importance: normal
> > > Priority: normal
> > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> > > Newsgroups: microsoft.public.dotnet.framework.compactframework
> > > NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> > > Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> > > Xref: cpmsftngxa10.phx.gbl
> > microsoft.public.dotnet.framework.compactframework:67045
> > > X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
> > >
> > > Thanks for your quick reply. I see what you are getting at. But how
would
> > a
> > > race condition cause a hang? I thought it usually just corrupts the
> > proper
> > > value of an object or variable.
> > >
> > > I'm getting quite worried because i have been working on this app for
> > quite
> > > some time now and to find out it can't last for long periods of time
is
> > > really disappointing. I just want to make sure whether things like
this
> > are
> > > fixable or if it's inherent with running multithreaded apps on
> > > resource-contrained devices. It's just very wierd that sometimes it
runs
> > for
> > > hours (it ran for 10 hours once) and at other times it freezes after
20,
> > or
> > > 30 mins or so. I'll have a look and see if i can find any race
> > conditions.
> > > Thanks in advance.
> > >
> > > Michael--J.
> > >
> > > "Ilya Tumanov [MS]" wrote:
> > >
> > > > You probably have a race condition somewhere; this is the common
reason
> > for
> > > > multithreaded applications to hang.
> > > >
> > > > Make sure all shared (between threads) objects are properly
> > locked/unlocked.
> > > >
> > > >
> > > >
> > > > Best regards,
> > > >
> > > >
> > > >
> > > > Ilya
> > > >
> > > >
> > > >
> > > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> > > >
> > > >
> > > > "Michael--J" <MichaelJ@discussions.microsoft.com> wrote in message
> > > > news:2A88D523-2302-4891-943E-2170F347100A@microsoft.com...
> > > > > Hi,
> > > > >
> > > > > I've written a C# console app that does a lot of things
> > simultaneously.
> > > > > The
> > > > > device being used is an FB6500
> > > > > (http://www.fabiatech.com/products/fb6500.htm)
> > > > > running Windows CE 5.0. These are all the things the app does:
> > > > >
> > > > > 1. Uses four threads to scan four COM ports - each port processes
> > real
> > > > > time
> > > > > data composed of packets. These packets are on average 25 bytes
long
> > and
> > > > > throughput is around 15 packets/sec. So all ports combined
process 60
> > > > > packets/sec.
> > > > >
> > > > > 2. Opens two network sockets - 1 for sending data and another for
> > > > > receiving.
> > > > > The receiving socket listens for incoming commands from a
connected
> > > > > client.
> > > > >
> > > > > 3. Uses 3 timers - one which runs every 10 seconds sends 1500
bytes
> > of
> > > > > data
> > > > > through a socket to a connected client, another which runs every
> > minute
> > > > > checks the status of certain variables, and the third runs every
hour
> > and
> > > > > uses RDA (remote data access) to synchronize a remote SQL Server
2000
> > > > > database.
> > > > >
> > > > > 4. Keeps a log of things that may happen by keeping a file open
and
> > > > > writing
> > > > > to it when necessary.
> > > > >
> > > > > I also need to run a client on a desktop PC which connects to the
> > > > > listening
> > > > > socket of the app on the device. This client simply receives the
1500
> > > > > bytes
> > > > > of data every ten seconds and updates a form. When running the
app on
> > the
> > > > > device, it works fine functionally but I have noticed that a lot
of
> > times
> > > > > the
> > > > > console app freezes after a while (the mouse is still movable but
I
> > can't
> > > > > press anything, the system time at the bottom right corner also
> > freezes).
> > > > > I
> > > > > ran it overnight last night and this morning when I checked it,
it
> > was
> > > > > still
> > > > > running. I then ran it again and after 20 mins or so it freezes.
The
> > > > > amount
> > > > > of time it takes until it freezes is unpredictable. The funny
thing
> > is
> > > > > when
> > > > > running it under VS.NET debug mode, after the app freezes, the
serial
> > > > > processing is still taking place, it's the networking stuff
that's
> > stopped
> > > > > (i.e. the client no longer receives the 1500 bytes every ten
secs).
> > Would
> > > > > the
> > > > > number of threads running cause this freezing to take place? I
> > honestly
> > > > > don't
> > > > > know where to begin to fix this problem. My app NEEDS to run for
long
> > > > > periods
> > > > > of time (i.e. over 12 hours). Can anyone shed any light on what
might
> > be
> > > > > causing this or where I should start looking? Thanks in advance.
> > > > >
> > > > > Kind Regards,
> > > > >
> > > > > Michael--J
> > > >
> > > >
> > > >
> > >
> >
> >
>



Relevant Pages

  • Re: Batch file and MFC (Properly Terminating Application)
    ... running any secondary modal loop. ... don't write an OnCancel handler, ... the changes the user thought had been made--because the app closed without ... user clicks on Cancel button and application exits. ...
    (microsoft.public.vc.mfc)
  • Re: Virus alert on my app??
    ... waste of battery energy if your app is merely polling something in a loop ... processor after it has offered it up until at least one time slot period has ... DoEvents does actually call Sleepbut either of them in a closed loop ...
    (microsoft.public.vb.general.discussion)
  • Re: Console app freezes
    ... It's not a while loop which checks for some ... You'll need to firure out what to do in case buffer overflows (terminate, ... > My app uses OpenNETCF.org’s serial comms code with a few modifications ... I couldn’t use a parity error event to ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: yield API
    ... Process A *could* immediately go into some kind of "check for file; sleep n ms" loop, but instead it starts off by calling sched_yieldto give process B a chance to run and hopefully get to the point where it has created the file before process A is again scheduled and starts to look for it - after the single sched yield call, process A does indeed go into a "check for file; sleep 250ms;" loop, but most of the time the initial sched_yieldcall actually results in the file being present without having to loop like that. ... Specifically, in the first case you tell the kernel "I'm waiting for something but I don't know what it is or how long it will take"; while in the second case you tell the kernel "I'm waiting for something that will take exactly X milliseconds, even though I don't know what it is. ... *is* an actual use of the API in a real app. ...
    (Linux-Kernel)
  • Re: eventhandler fires when a process(myProcess.GetProcesses) is missing
    ... If my vb.net app finds the calc.exe at form.load. ... If I close my vb program, it will be closed, but is still runningand waiting for the "waitforexit" of calc.exe. ...
    (microsoft.public.dotnet.languages.vb)