Path: utzoo!attcan!uunet!samsung!usc!snorkelwacker!bu.edu!xylogics!transfer!crackers!m2c!umvlsi!dime!smectos!james From: james@smectos.gang.umass.edu (Jim Riordan) Newsgroups: comp.sys.sgi Subject: m_kill_procs() and streams Keywords: multiprocessing Message-ID: <16658@dime.cs.umass.edu> Date: 10 Jul 90 00:18:29 GMT Sender: news@dime.cs.umass.edu Reply-To: james@smectos.gang.umass.edu (Jim Riordan) Organization: University of Massachusetts, Amherst Lines: 232 I have been trying to use the multiprocessing library in IRIX Release 3.2 but I am having trouble with m_kill_procs() interfering with streams. I have included a shar file demonstrating the problem. The program reads a stream and then does one a a few things according to the input. When I choose an option which uses the multiprocessing, characters on the stream after that option seem to get flushed. The 'h' routine does not use multiprocessing while the 'a' routine does. If I type "h h", then the 'h' routine gets called twice. If I type "h a a some_more_sufff", the 'h' routine gets executed, the 'a' routine gets called once and the program returns never having read the rest of the input. If the current stream is stdin, I can then continue. Streams other than stdin or pipes yield similiar results. If the answer is obvious, please responed/flame by email. Thanks in advance, -james +---------------+-----------------------+------------------------------+ | James Riordan | This space left blank | james@smectos.gang.umass.edu | +---------------+-----------------------+------------------------------+ x---x----x----x----x----x----x-CUT HERE-x----x----x----x----x----x----x #! /bin/sh # This is a shell archive. Kill anything before the /bin/sh line, then unpack # it by saving it into a file and typing sh file. To overwrite existing # files, type sh file -c. # Contents: problem # Wrapped by james@diogenes on Mon Jul 9 19:51:15 EDT 1990 PATH=/bin:/usr/bin:/usr/ucb;export PATH echo shar: making directory problem mkdir problem if test -f 'problem/ptest.c' -a "${1}" != "-c"; then echo shar: Will not clobber existing file \"'problem/ptest.c'\" else echo shar: Extracting \"'problem/ptest.c'\" \( 1736 characters \) sed "s/^X//" > 'problem/ptest.c' << 'THE-END-OF:problem/ptest.c' X#include X#include X#include X X#ifndef NPROCS X#define NPROCS 4 X#endif /* NPROCS */ X X Xvoid foo_bar() X{ X int count; X double foo = 0.0; X X fprintf (stderr, "."); X X#ifdef WATCH_GR_OSVIEW /* waste some parallel processor time */ X for (count = 0; count < 100000; count++) foo = (foo + foo)/2.0; X#endif /* WATCH_GR_OSVIEW */ X} X X Xvoid par_apply_fun (void (*func)()) X{ X unsigned int count; X X for (count = m_get_myid(); count < 64; count += NPROCS) { X func(); X }; X X m_sync(); X} X Xvoid p_apply_fun (void ((*func)())) X{ X m_set_procs (NPROCS); X X if (m_fork (par_apply_fun, func)) { X perror ("\nm_fork\n"); X }; X X if (m_kill_procs ()) { X perror ("\nm_kill_procs: "); X }; X} X Xint main(int argc, char **argv) X{ X FILE *command = stdin; X char action; X X if (argc == 2) { X command = fopen (argv[1], "r"); X if (!command) { X fprintf ("Unable to open %s. Reverting to stding.\n", argv[1]); X command = stdin; X }; X }; X X fprintf (stdout, "test: "); X X while ((action != 'q')&&!feof(command)) { /* main event loop */ X X fscanf (command, "%c", &action); X switch (action) { X X case 'a': X p_apply_fun (foo_bar); X fprintf (stdout, "\nDone.\ntest: "); X break; X X case 'h': X fprintf (stdout, "This is a test.\n"); X break; X X case '?': X fprintf (stdout, "a\tFork and kill some useless process\n"); X fprintf (stdout, "h\tPrint a meaningless meassage.\n"); X break; X X case '\t': X case ' ': X case 'q': X break; X X case '\n': X fprintf (stdout,"test: "); X break; X X default: X fprintf (stderr, "No such option (try ?).\n"); X fflush (stderr); X break; X }; X }; X X fclose (command); X exit (0); X}; X X X X X X X X X X X THE-END-OF:problem/ptest.c if test 1736 -ne `wc -c <'problem/ptest.c'`; then echo shar: \"'problem/ptest.c'\" unpacked with wrong size! fi # end of 'problem/ptest.c' fi if test -f 'problem/Makefile' -a "${1}" != "-c"; then echo shar: Will not clobber existing file \"'problem/Makefile'\" else echo shar: Extracting \"'problem/Makefile'\" \( 202 characters \) sed "s/^X//" > 'problem/Makefile' << 'THE-END-OF:problem/Makefile' XCC = cc XCFLAGS = -g -lmpc XDEFS = -DNPROCS=4 -DWATCH_GR_OSVIEW X X Xall: ptest X Xptest: ptest.c X $(CC) ptest.c $(DEFS) $(CFLAGS) -o ptest X Xclean: X -/bin/rm -f a.out ptest X -/bin/rm -f *~ X -/bin/rm -f *.o X X THE-END-OF:problem/Makefile if test 202 -ne `wc -c <'problem/Makefile'`; then echo shar: \"'problem/Makefile'\" unpacked with wrong size! fi # end of 'problem/Makefile' fi if test -f 'problem/example_0' -a "${1}" != "-c"; then echo shar: Will not clobber existing file \"'problem/example_0'\" else echo shar: Extracting \"'problem/example_0'\" \( 14 characters \) sed "s/^X//" > 'problem/example_0' << 'THE-END-OF:problem/example_0' Xh h h h X? Xh Xq THE-END-OF:problem/example_0 if test 14 -ne `wc -c <'problem/example_0'`; then echo shar: \"'problem/example_0'\" unpacked with wrong size! fi # end of 'problem/example_0' fi if test -f 'problem/example_1' -a "${1}" != "-c"; then echo shar: Will not clobber existing file \"'problem/example_1'\" else echo shar: Extracting \"'problem/example_1'\" \( 10 characters \) sed "s/^X//" > 'problem/example_1' << 'THE-END-OF:problem/example_1' Xh Xh Xa Xh Xq THE-END-OF:problem/example_1 if test 10 -ne `wc -c <'problem/example_1'`; then echo shar: \"'problem/example_1'\" unpacked with wrong size! fi # end of 'problem/example_1' fi if test -f 'problem/README' -a "${1}" != "-c"; then echo shar: Will not clobber existing file \"'problem/README'\" else echo shar: Extracting \"'problem/README'\" \( 122 characters \) sed "s/^X//" > 'problem/README' << 'THE-END-OF:problem/README' XFor amusement try: X Xdiogenes% ptest example_0 /* behaves nicely */ Xdiogenes% ptest example_1 /* does not behave nicely */ THE-END-OF:problem/README if test 122 -ne `wc -c <'problem/README'`; then echo shar: \"'problem/README'\" unpacked with wrong size! fi # end of 'problem/README' fi echo shar: End of shell archive exit 0