9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: dhog@plan9.bell-labs.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] C-program error..
Date: Fri, 16 Jun 2000 15:50:42 -0400	[thread overview]
Message-ID: <200006161950.PAA05591@cse.psu.edu> (raw)

In your example, s in recvit() is expected (by recv()) to point to
storage for the data sent on the channel (all 32 bytes worth),
but you have left it uninitialized.

Also, print() has an internal buffer of 4096 bytes; you need to
increase the stack size or you'll get mysterious errors caused
by stack corruption.

Try this version:

#include <u.h>
#include <libc.h>
#include <thread.h>

#define STACKSIZE (8*1024)

void
recvit(void *arg)
{
	char *s;
	Channel *in = arg;

	recv(in, &s);
	print("%s\n", s);
	free(s);
}

void
threadmain(int argc, char *argv[])
{
	char *m;
	Channel *sch;

	sch = chancreate(sizeof(char*), 0);
	m = strdup("hello world!");
	print("main: %s\n", m);
	proccreate(recvit, (void *)sch, STACKSIZE);

	send(sch, &m);

	print("done\n");
}



             reply	other threads:[~2000-06-16 19:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-16 19:50 dhog [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-06-16 19:52 rsc
2000-06-16 18:57 Ish Rattan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200006161950.PAA05591@cse.psu.edu \
    --to=dhog@plan9.bell-labs.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).