Welcome, Guest. Please login or register.

Author Topic: CreateNewProc bug in SASC ?  (Read 5599 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« on: August 19, 2007, 12:59:08 PM »
Your bug: stdio is not thread safe.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #1 on: August 19, 2007, 01:08:04 PM »
@ChaosLord

printf() works inside Forbid() just fine (tho it is bad style IMO). Forbid() is broken when needed.

Permit() is not needed at the end of a subprocess. In fact, it's often useful to avoid the parent being allowed to run before the subprocess has terminated.

The real problem is that stdio is not thread safe.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #2 on: August 19, 2007, 01:45:08 PM »
@ChaosLord
Quote
Can a regular Process with no children or parents, do a Forbid() without Permit() near the end?

For example a CLI command?

No.

Well it can, but that is a bug (the CLI will then inherit the pending Forbid, and it will cause all sorts of nasty things).
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #3 on: August 19, 2007, 03:31:09 PM »
@Georg
Quote
If you are lucky enough not to be screwed by the process cleanup routines if the they do something which calls Wait() and breaks Forbid() state.

Screwed how? The execution is inside the OS now, and will not return to the seglist, so the seglist can disappear as soon as the final 'rts' has executed.

The Forbid() is there only to ensure that the final couple of instructions (typically poking some flag or calling ReplyMsg()) can execute without the seglist being unloaded under it.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #4 on: August 19, 2007, 05:43:50 PM »
@Thomas

Good point. That is the reason for outright crash.

However, even with __saveds it won't be safe... Neither SAS/C stdio, nor dos.library buffered I/O is thread safe.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #5 on: August 19, 2007, 10:01:31 PM »
Quote
Is stdio "Resident safe"?

By default it isn't.

How to create a residentable (or pure) application depends on the compiler. For example one SAS/C you link against LIB:cres.o. With gcc you use -resident switch (should work with ixemul at least). I'm not familiar with VBCC.

This applies to c-library stdio. If you use dos.library stuff and keep all variables local then these restrictions do not apply, obviously. That way it's possible to do pure applications even without any startup or stdlib code, for example.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #6 on: August 19, 2007, 11:23:56 PM »
@Jose
Quote
As for stdio not being thread safe. I've debugged various multithreaded functions in the past and worst result I've had AFAIremember was the text output being mixed up, but no crashes.

It can crash, it's just not very likely to happen.

However, in my personal opinion nothing is more annoying than rare, untrackable crashes.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CreateNewProc bug in SASC ?
« Reply #7 on: September 19, 2007, 01:17:31 PM »
Quote
Try with this code, it certainly work better.

Actually it doesn't. dos.library buffered I/O isn't thread safe (that is, you cannot safely access buffered filehandle from multiple processes). The filehandle buffer isn't protected against simultanous access, so if you're unlucky things can go badly wrong.

If you print just couple of lines it's not very likely to break, however.