ftmemsim-valgrind/tests/blocked_syscall.c
Julian Seward 7a36f60133 Mega-merge of my last 2 weeks hacking. This basically does the groundwork
for pthread_* support.  Major changes:

* Valgrind now contains a (skeletal!) user-space pthreads
  implementation.  The exciting bits are in new file vg_scheduler.c.
  This contains thread management and scheduling, including nasty crud
  to do with making some syscalls (read,write,nanosleep) nonblocking.
  Also implementation of pthread_ functions: create join
  mutex_{create,destroy,lock,unlock} and cancel.

* As a side effect of the above, major improvements to signal handling
  and to the client-request machinery.  This is now used to intercept
  malloc/free etc too; the hacky way this is done before is gone.
  Another side effect is that vg_dispatch.S is greatly simplified.
  Also, the horrible hacks to do with delivering signals to threads
  blocked in syscalls are gone, since the new mechanisms cover this case
  easily.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@52
2002-04-12 11:12:52 +00:00

33 lines
645 B
C

#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
int fds[2];
void the_sighandler ( int signo )
{
int nw;
// assert(signo == SIGUSR1);
printf("sighandler running; should unblock now\n");
nw = write(fds[1], "zzz", 1);
// assert(nw == 1);
}
int main ( void )
{
char buf[10];
int res, nr;
void* oldsh = signal(SIGUSR1, the_sighandler);
assert(oldsh != SIG_ERR);
printf("pid = %d\n", getpid());
res = pipe(fds);
assert (res == 0);
printf("doing read(); this should block\n");
nr = read(fds[0], buf, 1);
/* blocks */
printf("read returned %d\n", nr);
return 0;
}