Why doesn't this simple two line program work ...

Bob Lantz lantz at Apple.COM
Fri Jan 4 07:58:23 AEST 1991


Tony,

You wrote:

>Here is a simple program that works fine when the value 20 is replaced by a
>smaller integer. But when 20 or more lines are printed the program does not
>do anything - it just hangs forever.

>main()
>{
>    register int j;

>    for (j = 0; j < 20; j++)
>	write(1, "Why doesnt this program work for 20?\n", 37);
>}


>Pretty simple program huh? It is shorter than the commands to compile and link
>it.  It is linked to run under A/UX in the MacOS environment (naturally it
>runs fine as a pure UNIX program).

>What am I doing wrong?

You aren't calling WaitNextEvent, EventAvail, or any of the other traps
which give control back to MultiFinder and allow CommandShell to run.

Programs which run in the MacOS environment must be MultiFinder-friendly;
this means, generally, that they must not make blocking system calls.
In your case, you are writing a bunch of data which never gets read by
CommandShell, so your write blocks.  This can be fixed by putting
an EventAvail call in your write loop so CommandShell can run.

This is not necessary (nor, in fact, will it work) for programs which
aren't linked with the Mac libraries and which do not attach to the Mac
environment.

>Cheers,
>Tony Cooper
>sramtrc at albert.dsir.govt.nz

Bob Lantz
A/UX Team



More information about the Comp.unix.aux mailing list