Subj : Re: Futex problem To : comp.programming.threads From : Joe Seigh Date : Sat Oct 01 2005 12:50 pm JK wrote: > Hi, I am trying to learn how to use futex and I just dont get it ;) > What is problem with this code example? The child process never stops > waiting. This is only a test, thats why it does not have any error > checking. > > > #include > #include > #include > #include > #include > #include > #include > > #define __NR_sys_futex __NR_futex > _syscall4(int, sys_futex, volatile int *, futex, int, op, > int, val, struct timespec *, rel); > > > int main(int argc, char *argv[]) > { > int counter = 1; > pid_t p = fork(); > > if (p == 0) > { > printf ("before wait\n"); > sys_futex(&counter, FUTEX_WAIT, 1, NULL); > printf ("after wait\n"); > } > > sleep (2); > > counter = 0; > printf ("wake (%d) : %d\n", sys_futex(&counter, > FUTEX_WAKE, 1, NULL), counter); > > sleep (2); > return EXIT_SUCCESS; > } > The futex needs to be in shared memory. Forked processes don't share memory. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .