Re: Signals and threads



Hello Thomas,

Finally, how do you send the SIGUSR1 to your threadA?

its pthread_kill(threadId,SIGUSR1);

It is difficult for us to help you, as we (obviously) do not have the
particular version "libpthread" that you have...

Could you please compile the program below and send us the
corresponding trace file:
$ strace -f -o trace.txt binaryName

Thanks,
Loic.

/*
compile: gcc -pthread try.c -o try
trace : strace -f -o trace.txt ./try
*/
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <assert.h>

void
handlerOne(int signo)
{
write(STDOUT_FILENO, "1", 1);
}

void
handlerTwo(int signo)
{
write(STDOUT_FILENO, "2", 1);
}

typedef void (*sighand_t)(int);

void*
thread(void* arg)
{
struct sigaction act;
sigset_t set;

sigemptyset(&set);
sigaddset(&set, SIGUSR1);
act.sa_handler = (sighand_t) arg;
act.sa_mask = set;
act.sa_flags = 0;
sigaction(SIGUSR1, &act, 0);
for (;;) {
sleep(1000);
}
return 0;
}

int main()
{
pthread_t tid1, tid2;

int rc = pthread_create(&tid1, 0, thread, (void*) handlerOne );
assert (rc==0 && "pthread_create");
sleep(1);
rc = pthread_create(&tid2, 0, thread, (void*) handlerTwo);
assert (rc==0 && "pthread_create");

sleep(1);
pthread_kill(tid1, SIGUSR1);
sleep(1);
pthread_kill(tid2, SIGUSR1);

sleep(1);
return 0;
}

.



Relevant Pages

  • Re: menu-based console application
    ... typedef void; ... struct MenuEntry ... Compile everything, fix typing errors and run the program. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: CFile and FILE*
    ... ever call exit() in any C++ ... LPVOID, e.g., ... void DoSomething ... Note that you can still compile this as C ...
    (microsoft.public.vc.mfc)
  • Re: A non-const reference may only be bound to an lvalue?
    ... To my surprise, I have tested that the following code can compile, ... struct X { ... void f; ... There are legitimate reasons to want to do that, but I've come to accept it ...
    (microsoft.public.vc.language)
  • Re: Library bug or my fault?
    ... void memcpy ... struct Foo { ... 29 void cp(const Foo *foo) ... You have no definition for cp2so the code above won't compile. ...
    (comp.lang.c)
  • SUMMARY: void main(int argc, char *argv[]) question
    ... The consensus is that the use of void on main is wrong (The book ... return and int. ... >In trying to compile some old test Unix C programs... ... Why do those old UNIX programs used void ... ...
    (SunManagers)