Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (63 sloc) 1.867 kb
f42d421d »
2010-12-07 first commit. pluton framework
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <time.h>
4
5 #include <string>
6 #include <iostream>
7
8 #include <st.h>
9
10 using namespace std;
11
12 #include "pluton/client.h"
13
14 //////////////////////////////////////////////////////////////////////
15 // Test the threaded interface to the pluton client library.
16 //////////////////////////////////////////////////////////////////////
17
18
19 class myMutex {
20 public:
21 st_mutex_t mutex;
22 };
23
24 // Need to fake out that we're all the same thread to avoid another assert test
25
26 static pluton::thread_t
27 tSelf(const char* who)
28 {
29 // st_thread_t self = st_thread_self();
30 st_thread_t self = 0;
31 clog << "tSelf called by " << who << " returning " << (void*)(self) << endl;
32
33 return reinterpret_cast<pluton::thread_t>(self);
34 }
35
36 void*
37 tStart(void* a1)
38 {
39 pluton::client* C = (pluton::client*)(a1);
40
41 pluton::clientRequest R;
42 R.setContext("echo.log", "y");
43 R.setContext("echo.sleepMS", "3000");
44 R.setRequestData("ok");
45 if (!C->addRequest("system.echo.0.raw", &R)) {
46 clog << C->getFault().getMessage("Fatal: addRequest(R) failed in tThread4") << endl;
47 exit(3);
48 }
49
50 if (C->executeAndWaitAll() <= 0) {
51 clog << C->getFault().getMessage("Fatal: executeAndWaitAll() failed in tThread4") << endl;
52 exit(4);
53 }
54
55 return 0;
56 }
57
58
59 int
60 main(int argc, char** argv)
61 {
62 st_init();
63
64 pluton::client::setThreadHandlers(tSelf);
65
66 pluton::client C("tThread4");
67 if (!C.initialize(argv[1])) {
68 clog << C.getFault().getMessage("Fatal: initialize() failed in tThread1") << endl;
69 exit(1);
70 }
71
72 C.setPollProxy(st_poll);
73 st_thread_t t1, t2;
74 t1 = st_thread_create(tStart, (void*)(&C), 1, 0);
75 st_sleep(1);
76 t2 = st_thread_create(tStart, (void*)(&C), 1, 0); // Use the same client - a nono
77
78 clog << "Waiting on t1" << endl;
79 st_thread_join(t1, 0);
80
81 clog << "Waiting on t2" << endl;
82 st_thread_join(t2, 0);
83
84 exit(0);
85 }
Something went wrong with that request. Please try again.