Welcome, Guest. Please login or register.

Author Topic: CreateNewProcTags() over sasc and vbcc  (Read 5519 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline kas1eTopic starter

CreateNewProcTags() over sasc and vbcc
« on: April 11, 2006, 03:59:23 PM »
Here is example:
Code: [Select]

#include <dos/dostags.h>
#include <proto/dos.h>
#include <proto/exec.h>

struct Process *player;

__saveds void play_module(void)
{

Printf(&quot;ooooo\n&quot;);
Printf(&quot;uuuu\n&quot;);
Printf(&quot;ieeetss\n&quot;);
}

int main(void)
{

printf(&quot;first\n&quot;);

player = CreateNewProcTags(
NP_Entry, &play_module,
NP_Priority, 1,
NP_Name, &quot;Player Process&quot;,
TAG_DONE);

printf(&quot;second\n&quot;);
Delay(200);
printf(&quot;third\n&quot;);

}

so, result:
Code: [Select]

work:programming>spawn_vbcc
first
ooooo
uuuu
ieeetss
second
third

work:programming>spawn_sasc
first
second
third
work:programming>

It looks like  over vbcc it works, over sasc - not. If i add (for example) in span thread a fucntion like SystemTagList("newcli",0); over vbcc is works, over sasc - reboot with red flashing of screen.

by default i have nosmalldata and nosmallcode in sasc options. Any idea how it must be looks like ?:)
 

Offline _yak_

  • Full Member
  • ***
  • Join Date: Mar 2006
  • Posts: 227
    • Show only replies by _yak_
Re: CreateNewProcTags() over sasc and vbcc
« Reply #1 on: April 11, 2006, 04:18:13 PM »
I'm not sure but according to AutoDocs, processes created by CreateNewProc() by default have assigned both input and output to opens of NIL:. Try adding these tags:

NP_Input,stdin,
NP_Output,stdout,

This should fix the problem with not displaying anything from the child process on SAS/C. However, I'm not sure about the hang, take a look into dos/dostags.h, maybe there are some other tags you have to use...
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #2 on: April 11, 2006, 04:27:20 PM »
was try also this:
Code: [Select]

player = CreateNewProcTags(
NP_Entry, &play_module,
NP_Priority, 1,
NP_Name, &quot;Player Process&quot;,
NP_Input, Input(),
NP_CloseInput, FALSE,
NP_Output, Output(),
NP_CloseOutput, FALSE,
TAG_DONE);


the same. also, why it works over vbcc, and do not works over sasc ?
 

Offline _yak_

  • Full Member
  • ***
  • Join Date: Mar 2006
  • Posts: 227
    • Show only replies by _yak_
Re: CreateNewProcTags() over sasc and vbcc
« Reply #3 on: April 11, 2006, 05:59:37 PM »
@ kas1e

Hmmm, I've given my hints out of my memory (currently I'm not programming for Amiga). Therefore I forgot many things and now I'm not sure if this "NP_Input,stdin," (and same for output) would actualy work? Or "Input()" and "Output()" functions have to be used instead?
 

Offline Jose

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: CreateNewProcTags() over sasc and vbcc
« Reply #4 on: April 21, 2006, 12:38:11 AM »
@Kas1e

"NP_Entry, &play_module"

Shouldn't that be "NP_Entry, play_module" ?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: CreateNewProcTags() over sasc and vbcc
« Reply #5 on: April 21, 2006, 01:41:22 AM »
You must not do buffered I/O from multiple processes, dos.library filehandles are NOT semaphore protected (nor are most libnix stdio implementations). The behaviour is undefined. If you must output some debug from the sub thread, use kprintf.

Mixing dos.library and stdio I/O result in undefined behaviour.

Don't trust on priorities when doing multiprocess apps, this will break eventually. Use interprocess communcation, see IPC example (Note: This particular example uses 2nd LoadSeg()d function as the 2nd process. It could aswell be another function.)
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #6 on: May 12, 2006, 12:21:30 PM »
@piru
Thanks for good answer, but question is still here:
why CreateNewProcTags do not works over sasc, and the same code works ok on vbcc ? Maybe someone have little example for sasc how it must be used ?

I do not mean with printf, any example will be good. Just spawning a new console, or write somethink to file. In other words, anythink that will show , that proccess is created and works (i mean over sasc of course).
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: CreateNewProcTags() over sasc and vbcc
« Reply #7 on: May 12, 2006, 12:38:14 PM »
@kas1e
Quote
why CreateNewProcTags do not works over sasc, and the same code works ok on vbcc ?

I guess you missed my point: CreateNewProcTags works just fine, but using Printf for output does not.

Maybe this'll explain it best:
Code: [Select]

#include <dos/dostags.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <clib/debug_protos.h>

struct Process *player;
static volatile int quit;

__saveds void play_module(void)
{
  kprintf(&quot;ooooo\n&quot;);
  kprintf(&quot;uuuu\n&quot;);
  kprintf(&quot;ieeetss\n&quot;);
  Forbid();
  quit = 1;
}

int main(void)
{
  kprintf(&quot;first\n&quot;);

  player = CreateNewProcTags(
    NP_Entry, &play_module,
    NP_Priority, 1,
    NP_Name, &quot;Player Process&quot;,
    TAG_DONE);

  if (player)
  {
    kprintf(&quot;second\n&quot;);
    while (!quit)
    {
      Delay(20);
    }
    kprintf(&quot;third\n&quot;);
  }
  return 0;
}


compile with: sc nostkchk link test.c lib lib:debug.lib

UPDATE: stack check would screw it up before, sorry for not figuring it out earlier ;-)
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #8 on: May 12, 2006, 06:48:44 PM »
@piru
maybe it's strange, but i copy your example 1:1, and do compiling as you said 1:1 too. After running - freeze or reboot or red flashing screen.

I tryed it on winuae, but the same code over vbcc works just fine. I also try it on my a1200/060. After running nothink happenes. CPU is loaded on 100%.

maybe will be matter version of sasc which i am using. On compiling stage it sais: SAS/C amiga compiper 6.50
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: CreateNewProcTags() over sasc and vbcc
« Reply #9 on: May 12, 2006, 06:53:11 PM »
I'm using SAS/C Amiga Compiler 6.58

You could try: sc resopt link test.c lib lib:debug.lib
This should eliminate problems from some weird SCOPTS file.
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #10 on: May 12, 2006, 07:10:52 PM »
The same .. will try to upgrade to the 6.58 right now.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: CreateNewProcTags() over sasc and vbcc
« Reply #11 on: May 12, 2006, 07:12:44 PM »
I should prolly remind you that kprintf output is not seen normally (it's using the serial). You should probably use sashimi to grab it.
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #12 on: May 12, 2006, 07:17:54 PM »
The same .. will try to upgrade to the 6.58 right now.

edit: but 100% of cpu load it is not normal. and it's just must do kprintfs (so be not to console), and exit. But is always in freeze state.

btw, if i will put in newproc SystemTagList("newcli",0); without any printfs/kprintfs it must spawn a shell i think ?
 

Offline kas1eTopic starter

Re: CreateNewProcTags() over sasc and vbcc
« Reply #13 on: May 13, 2006, 09:39:48 AM »
after patch to 6.55. it works, but very strange. sometimes it runs ok , sometimes not. sometimes it run ok from golded ide, sometimes not. from the shell, or from icon, or from dopus - can't run always (faulth is here).

for you it's just works always ? in the shell, from icon, etc ?

right now, i just recopy your example, go to the shell, and put your compiling string:
Code: [Select]

work:programming>sc resopt link spawn_thread.c lib lib:debug.lib
SAS/C Amiga Compiler 6.58
Copyright (c) 1988-1995 SAS Institute Inc.
Slink - Version 6.58
Copyright (c) 1988-1995 SAS Institute, Inc.  All Rights Reserved.

SLINK Complete - Maximum code size = 1948 ($0000079c) bytes

Final output file size = 2540 ($000009ec) bytes
work:programming>spawn_thread

and faulth is here.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: CreateNewProcTags() over sasc and vbcc
« Reply #14 on: May 13, 2006, 10:11:24 AM »
It was the stack check code screwing it up. nostkchk cures it.

More explanation: It would compare the stack pointer for overflow at play_module, and if the pointer was lower than the limit set at startup code, it would set up a requester and exit. However, play_module was run on context of a second process, and thus stack pointer was randomly either before or after the main task stack. This is why it failed randomly.

I've updated the code to poll some variable for termination aswell, far from perfect but at least it should never crash now.