13
0

Add tool to test PBD::signal d'tor race-condition

This commit is contained in:
Robin Gareus 2021-11-20 18:38:53 +01:00
parent 7580d6aba7
commit ba1e2d13c5
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,18 @@
AD = ../..
CXXFLAGS = -Wall -pthread -g
CPPFLAGS = -I $(AD)/libs/pbd -I $(AD)/build/libs/pbd
CPPFLAGS += `pkg-config --cflags glibmm-2.4`
LDFLAGS = -L$(AD)/build/libs/pbd -Wl,-rpath=$(AD)/build/libs/pbd
LDLIBS = `pkg-config --libs glibmm-2.4` -lpbd
signal-test: signal-test.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ signal-test.cc $(LDLIBS)
clean:
rm -f signal-test
test: signal-test
while test $$? = 0 ; do echo -n "."; ./signal-test; done
.PHONY: clean test

View File

@ -0,0 +1,65 @@
#include <cstdint>
#include <cstdlib>
#include <pthread.h>
#include "pbd/pbd.h"
#include "pbd/signals.h"
class Tx {
public:
PBD::Signal1<void, int> sig1;
};
class Rx {
public:
Rx (Tx& sender) {
sender.sig1.connect_same_thread (_connection, boost::bind (&Rx::cb, this, _1));
}
private:
void cb (int i) {
printf ("CB %d\n", i);
}
PBD::ScopedConnection _connection;
};
pthread_barrier_t barrier;
static void* delete_t (void* arg) {
Tx* t = static_cast<Tx*> (arg);
pthread_barrier_wait (&barrier);
delete t;
//printf ("Deleted tx\n");
return 0;
}
static void* delete_r (void* arg) {
Rx* r = static_cast<Rx*> (arg);
pthread_barrier_wait (&barrier);
delete r;
//printf ("Deleted rx\n");
return 0;
}
int
main (int argc, char** argv)
{
PBD::init ();
Tx* t = new Tx ();
Rx* r = new Rx (*t);
//t->sig1 (11); /* EMIT SIGNAL */
pthread_barrier_init (&barrier, NULL, 2);
pthread_t dt, dr;
pthread_create (&dt, NULL, delete_t, (void*)t);
pthread_create (&dr, NULL, delete_r, (void*)r);
pthread_join (dt, NULL);
pthread_join (dr, NULL);
pthread_barrier_destroy (&barrier);
PBD::cleanup ();
return 0;
}