Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 82bbab17c0
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (63 sloc) 1.867 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#include <string>
#include <iostream>

#include <st.h>

using namespace std;

#include "pluton/client.h"

//////////////////////////////////////////////////////////////////////
// Test the threaded interface to the pluton client library.
//////////////////////////////////////////////////////////////////////


class myMutex {
public:
  st_mutex_t mutex;
};

// Need to fake out that we're all the same thread to avoid another assert test

static pluton::thread_t
tSelf(const char* who)
{
  // st_thread_t self = st_thread_self();
  st_thread_t self = 0;
  clog << "tSelf called by " << who << " returning " << (void*)(self) << endl;

  return reinterpret_cast<pluton::thread_t>(self);
}

void*
tStart(void* a1)
{
  pluton::client* C = (pluton::client*)(a1);

  pluton::clientRequest R;
  R.setContext("echo.log", "y");
  R.setContext("echo.sleepMS", "3000");
  R.setRequestData("ok");
  if (!C->addRequest("system.echo.0.raw", &R)) {
    clog << C->getFault().getMessage("Fatal: addRequest(R) failed in tThread4") << endl;
    exit(3);
  }

  if (C->executeAndWaitAll() <= 0) {
    clog << C->getFault().getMessage("Fatal: executeAndWaitAll() failed in tThread4") << endl;
    exit(4);
  }

  return 0;
}


int
main(int argc, char** argv)
{
  st_init();

  pluton::client::setThreadHandlers(tSelf);

  pluton::client C("tThread4");
  if (!C.initialize(argv[1])) {
    clog << C.getFault().getMessage("Fatal: initialize() failed in tThread1") << endl;
    exit(1);
  }

  C.setPollProxy(st_poll);
  st_thread_t t1, t2;
  t1 = st_thread_create(tStart, (void*)(&C), 1, 0);
  st_sleep(1);
  t2 = st_thread_create(tStart, (void*)(&C), 1, 0); // Use the same client - a nono

  clog << "Waiting on t1" << endl;
  st_thread_join(t1, 0);

  clog << "Waiting on t2" << endl;
  st_thread_join(t2, 0);

  exit(0);
}
Something went wrong with that request. Please try again.