2021-11-20 12:38:53 -05:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "pbd/pbd.h"
|
|
|
|
#include "pbd/signals.h"
|
2021-11-20 22:11:22 -05:00
|
|
|
#include "pbd/event_loop.h"
|
2021-11-20 12:38:53 -05:00
|
|
|
|
|
|
|
class Tx {
|
|
|
|
public:
|
|
|
|
PBD::Signal1<void, int> sig1;
|
|
|
|
};
|
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
/* ****************************************************************************/
|
|
|
|
|
|
|
|
class Rx1 {
|
2021-11-20 12:38:53 -05:00
|
|
|
public:
|
2021-11-20 22:11:22 -05:00
|
|
|
Rx1 (Tx& sender) {
|
|
|
|
sender.sig1.connect_same_thread (_connection, boost::bind (&Rx1::cb, this, _1));
|
2021-11-20 12:38:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cb (int i) {
|
2021-11-20 22:11:22 -05:00
|
|
|
printf ("Rx1 %d\n", i);
|
2021-11-20 12:38:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PBD::ScopedConnection _connection;
|
|
|
|
};
|
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
/* ****************************************************************************/
|
|
|
|
|
|
|
|
struct MyInvalidationRecord : public PBD::EventLoop::InvalidationRecord
|
|
|
|
{
|
|
|
|
~MyInvalidationRecord () {
|
|
|
|
assert (use_count () == 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MyInvalidationRecord _ir;
|
|
|
|
|
|
|
|
class Rx2 : public PBD::ScopedConnectionList {
|
|
|
|
public:
|
|
|
|
Rx2 (Tx& sender) {
|
|
|
|
sender.sig1.connect (*this, &_ir, boost::bind (&Rx2::cb, this, _1), /* PBD::EventLoop */ 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cb (int i) {
|
|
|
|
printf ("CB %d\n", i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ****************************************************************************/
|
|
|
|
|
2021-11-20 12:38:53 -05:00
|
|
|
pthread_barrier_t barrier;
|
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
static void* delete_tx (void* arg) {
|
|
|
|
Tx* tx = static_cast<Tx*> (arg);
|
2021-11-20 12:38:53 -05:00
|
|
|
pthread_barrier_wait (&barrier);
|
2021-11-20 22:11:22 -05:00
|
|
|
delete tx;
|
2021-11-20 12:38:53 -05:00
|
|
|
//printf ("Deleted tx\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
static void* delete_rx1 (void* arg) {
|
|
|
|
Rx1* rx1 = static_cast<Rx1*> (arg);
|
2021-11-20 12:38:53 -05:00
|
|
|
pthread_barrier_wait (&barrier);
|
2021-11-20 22:11:22 -05:00
|
|
|
delete rx1;
|
|
|
|
//printf ("Deleted rx1\n");
|
2021-11-20 12:38:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
static void* delete_rx2 (void* arg) {
|
|
|
|
Rx2* rx2 = static_cast<Rx2*> (arg);
|
|
|
|
pthread_barrier_wait (&barrier);
|
|
|
|
delete rx2;
|
|
|
|
//printf ("Deleted rx2\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************************************************/
|
|
|
|
|
2021-11-20 12:38:53 -05:00
|
|
|
int
|
|
|
|
main (int argc, char** argv)
|
|
|
|
{
|
|
|
|
PBD::init ();
|
2021-11-20 22:11:22 -05:00
|
|
|
Tx* tx = new Tx ();
|
|
|
|
Rx1* rx1 = new Rx1 (*tx);
|
|
|
|
Rx2* rx2 = new Rx2 (*tx);
|
2021-11-20 12:38:53 -05:00
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
pthread_barrier_init (&barrier, NULL, 3);
|
|
|
|
pthread_t t[3];
|
2021-11-20 12:38:53 -05:00
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
pthread_create (&t[0], NULL, delete_tx, (void*)tx);
|
|
|
|
pthread_create (&t[1], NULL, delete_rx1, (void*)rx1);
|
|
|
|
pthread_create (&t[2], NULL, delete_rx2, (void*)rx2);
|
2021-11-20 12:38:53 -05:00
|
|
|
|
2021-11-20 22:11:22 -05:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
pthread_join (t[i], NULL);
|
|
|
|
}
|
2021-11-20 12:38:53 -05:00
|
|
|
|
|
|
|
pthread_barrier_destroy (&barrier);
|
|
|
|
PBD::cleanup ();
|
|
|
|
return 0;
|
|
|
|
}
|