Is writeFile() reentrant? 
Author Message
 Is writeFile() reentrant?

Hi,

I have an obscure problem!  I am using writeFile() to output debug
messages to an RS232 port.  The output function is called from various
threads on different levels.  Normally everything is fine but
occasionally the system hangs.  It looks like writeFile() allows a task
switch to a lower (or higher) priority thread.  If this second thread
calls writeFile() it normally works ok.  However, sometimes it doesn't
return.  Every subsequent call to writeFile() will also not return until
all relevant threads have hung.

I have written a simple test routine that creates up to 4 threads on
different priorities that simply sleep for 100ms then output an ASCII
buffer of ~80 characters repeatedly.  It usually hangs within a few
minutes.  Strangely, it fails quicker with the sleep than without.

Has anyone else experienced this behaviour?

Thanks in advance,

 Rob

PS.  Incidentally, does anyone know whether writeFile() waits for the
message to be output before returning, or does it queue the message and
return?

  Rob.Davis.vcf
< 1K Download


Tue, 20 Sep 2005 16:43:20 GMT  
 Is writeFile() reentrant?
What OS?
How and where are you opening the file?
Does each thread write separate data or do they all try to write the same
string?
What are the thread priorities you are using?

--
~Demitri

(This posting is provided "AS IS" with no warranties, and confers no
rights.)


Quote:
> Hi,

> I have an obscure problem!  I am using writeFile() to output debug
> messages to an RS232 port.  The output function is called from various
> threads on different levels.  Normally everything is fine but
> occasionally the system hangs.  It looks like writeFile() allows a task
> switch to a lower (or higher) priority thread.  If this second thread
> calls writeFile() it normally works ok.  However, sometimes it doesn't
> return.  Every subsequent call to writeFile() will also not return until
> all relevant threads have hung.

> I have written a simple test routine that creates up to 4 threads on
> different priorities that simply sleep for 100ms then output an ASCII
> buffer of ~80 characters repeatedly.  It usually hangs within a few
> minutes.  Strangely, it fails quicker with the sleep than without.

> Has anyone else experienced this behaviour?

> Thanks in advance,

>  Rob

> PS.  Incidentally, does anyone know whether writeFile() waits for the
> message to be output before returning, or does it queue the message and
> return?



Wed, 21 Sep 2005 01:01:59 GMT  
 Is writeFile() reentrant?

See answers below:

Quote:

> What OS?

CE version 3.  Target is Arcom Gxm (x86).

Quote:
> How and where are you opening the file?

Serial port initialisation code, run on start of application:

{
 DCB serConfigDflt;
 COMMTIMEOUTS serTimeoutsDflt;

 // Set up 'serConfigDflt' with default port configuration
 serConfigDflt.DCBlength = sizeof(serConfigDflt); // Structure length
 serConfigDflt.BaudRate = CBR_19200;     // 19200 baud
 serConfigDflt.fBinary   = true;      // Binary mode; no EOF check
 serConfigDflt.fParity   = false;     // Disable parity checking
 serConfigDflt.fOutxCtsFlow = false;     // Don't use CTS o/p control
 serConfigDflt.fOutxDsrFlow = false;     // Don't use DSR o/p control
 serConfigDflt.fDtrControl = DTR_CONTROL_DISABLE; // Don't use DTR control
 serConfigDflt.fDsrSensitivity = false;
 serConfigDflt.fTXContinueOnXoff = true;    // XOFF continues Tx
 serConfigDflt.fOutX = false;      // Don't use Xon/Xoff
 serConfigDflt.fInX  = false;
 serConfigDflt.fErrorChar = false;     // Disable error replacement
 serConfigDflt.fNull = false;      // Disable null stripping
 serConfigDflt.fRtsControl = RTS_CONTROL_DISABLE; // Don't use RTS control
 serConfigDflt.fAbortOnError = false;    // Do not abort reads/writes on error

 serConfigDflt.ByteSize = 8;       // 8 bits per byte
 serConfigDflt.Parity   = NOPARITY;     // No parity (where enabled)
 serConfigDflt.StopBits = ONESTOPBIT;    // One stop bit

 // Set up 'serTimeoutsDflt' for default read/write timeouts:
 serTimeoutsDflt.ReadIntervalTimeout         = 0;
 serTimeoutsDflt.ReadTotalTimeoutMultiplier  = 0;
 serTimeoutsDflt.ReadTotalTimeoutConstant    = 0;
 serTimeoutsDflt.WriteTotalTimeoutMultiplier = 0;
 serTimeoutsDflt.WriteTotalTimeoutConstant   = 0;

  // Set up COMx for debug i/o
------------------------------------------------<
  hSerDebug = CreateFile (COM_DEBUG, GENERIC_READ | GENERIC_WRITE,
        0, NULL, OPEN_EXISTING, 0, NULL);
  if ( hSerDebug == INVALID_HANDLE_VALUE )
   reportFault(E_DSIF_CREATE);    // Fault handling
  else
  { // Set up 'serConfig' with port configuration differences
   DCB serConfig = serConfigDflt;

   // Set new configuration
   DWORD result = SetCommState (hSerDebug, &serConfig);
   if ( result == 0 )
   {
    reportFault(E_DSIF_WTCONF);
    CloseHandle(hSerDebug);
    hSerDebug = INVALID_HANDLE_VALUE; // Disable port
   }
   else
   { // Set up 'serTimeouts' with timeout differences
    COMMTIMEOUTS serTimeouts = serTimeoutsDflt;  // None.
    serTimeouts.ReadTotalTimeoutConstant = DEBUG_RTTC_MS;

    // Set new timeouts
    result = SetCommTimeouts (hSerDebug, &serTimeouts);
    if ( result == 0 )
    {
     reportFault(E_DSIF_WTTIME);
     CloseHandle(hSerDebug);
     hSerDebug = INVALID_HANDLE_VALUE; // Disable port
    }
    else
    {
     // Ensure RTS inactive (power-down enable)
     EscapeCommFunction(hSerDebug, CLRRTS);
    }
   }
  }
 }

Quote:
}

<

Quote:

> Does each thread write separate data or do they all try to write the same
> string?

In the test the strings are similar.  They differ only in that they output the
iteration of that thread.  In the application they would be completely
independent.

Quote:
> What are the thread priorities you are using?

205 and 180 in the test.
Quote:

> --
> ~Demitri

> (This posting is provided "AS IS" with no warranties, and confers no
> rights.)



> > Hi,

> > I have an obscure problem!  I am using writeFile() to output debug
> > messages to an RS232 port.  The output function is called from various
> > threads on different levels.  Normally everything is fine but
> > occasionally the system hangs.  It looks like writeFile() allows a task
> > switch to a lower (or higher) priority thread.  If this second thread
> > calls writeFile() it normally works ok.  However, sometimes it doesn't
> > return.  Every subsequent call to writeFile() will also not return until
> > all relevant threads have hung.

> > I have written a simple test routine that creates up to 4 threads on
> > different priorities that simply sleep for 100ms then output an ASCII
> > buffer of ~80 characters repeatedly.  It usually hangs within a few
> > minutes.  Strangely, it fails quicker with the sleep than without.

> > Has anyone else experienced this behaviour?

> > Thanks in advance,

> >  Rob

> > PS.  Incidentally, does anyone know whether writeFile() waits for the
> > message to be output before returning, or does it queue the message and
> > return?

  Rob.Davis.vcf
< 1K Download


Fri, 23 Sep 2005 16:14:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help : difference between reentrant & no-reentrant functions

2. I am new to programming and am lost

3. Concurrent use of non-reentrant DLL

4. How do I make a C# dll reentrant...

5. reentrant ANSI C library

6. Flex & Bison: Reentrant

7. flex reentrant problem

8. Reentrant Code

9. #define REENTRANT

10. #define REENTRANT

11. Reentrant code definition

12. what the heck is "reentrant"?

 

 
Powered by phpBB® Forum Software