Skip to content

Commit ff91757

Browse files
authored
ST: Research adds examples that demos pthread and helloworld. v6.0.118 (#3989)
1. `trunk/research/st/exceptions.cpp` About exceptions with ST, works well on linux and mac, not work on cygwin. 2. `trunk/research/st/pthreads.cpp` About pthreads with ST, works well on all platforms. 3. `trunk/research/st/hello.cpp` Hello world, without ST, works well on all platforms. 4. `trunk/research/st/hello-world.cpp` Hello world, with ST, works well on all platforms. 5. `trunk/research/st/hello-st.cpp` A very simple version for hello world with ST, works well on all platforms.
1 parent ce2ce15 commit ff91757

File tree

7 files changed

+113
-1
lines changed

7 files changed

+113
-1
lines changed

trunk/doc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v6-changes"></a>
88

99
## SRS 6.0 Changelog
10+
* v6.0, 2024-03-24, Merge [#3989](https://github.com/ossrs/srs/pull/3989): ST: Research adds examples that demos pthread and helloworld. v6.0.118 (#3989)
1011
* v6.0, 2024-03-19, Merge [#3958](https://github.com/ossrs/srs/pull/3958): Add a TCP proxy for debugging. v6.0.117 (#3958)
1112
* v6.0, 2024-03-20, Merge [#3964](https://github.com/ossrs/srs/pull/3964): WebRTC: Add support for A/V only WHEP/WHEP player. v6.0.116 (#3964)
1213
* v6.0, 2024-03-19, Merge [#3990](https://github.com/ossrs/srs/pull/3990): System: Disable feature that obtains versions and check features status. v6.0.115 (#3990)

trunk/research/st/exceptions.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
# !!! ST does not support C++ exceptions on cygwin !!!
3+
g++ exceptions.cpp ../../objs/st/libst.a -g -O0 -o exceptions && ./exceptions
4+
*/
5+
#include <stdio.h>
6+
#include <exception>
7+
#include "../../objs/st/st.h"
8+
9+
int handle_exception() {
10+
try {
11+
throw 3;
12+
} catch (...) {
13+
return 5;
14+
}
15+
}
16+
17+
void* foo(void* arg) {
18+
int r0 = handle_exception();
19+
printf("r0=%d\n", r0);
20+
return NULL;
21+
}
22+
23+
int main(int argc, char** argv) {
24+
st_init();
25+
st_thread_create(foo, NULL, 0, 0);
26+
st_thread_exit(NULL);
27+
return 0;
28+
}
29+

trunk/research/st/hello-st.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
g++ hello-st.cpp ../../objs/st/libst.a -g -O0 -o hello-st && ./hello-st
3+
*/
4+
#include <stdio.h>
5+
#include "../../objs/st/st.h"
6+
7+
void foo() {
8+
st_init();
9+
st_sleep(1);
10+
printf("Hello World, ST!\n");
11+
}
12+
13+
int main() {
14+
foo();
15+
return 0;
16+
}

trunk/research/st/hello-world.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
g++ hello-world.cpp ../../objs/st/libst.a -g -O0 -o hello-world && ./hello-world
3+
*/
4+
#include <stdio.h>
5+
#include "../../objs/st/st.h"
6+
7+
void foo() {
8+
st_init();
9+
10+
for (int i = 0; ; i++) {
11+
st_sleep(1);
12+
printf("#%d: main: working\n", i);
13+
}
14+
}
15+
16+
int main() {
17+
foo();
18+
return 0;
19+
}

trunk/research/st/hello.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
g++ hello.cpp -g -O0 -o hello && ./hello
3+
*/
4+
5+
void foo() {
6+
}
7+
8+
int main(int argc, char** argv) {
9+
foo();
10+
return 0;
11+
}

trunk/research/st/pthreads.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Directly compile c++ source and execute:
3+
g++ pthreads.cpp ../../objs/st/libst.a -g -O0 -o pthreads && ./pthreads
4+
*/
5+
#include <stdio.h>
6+
#include <pthread.h>
7+
#include "../../objs/st/st.h"
8+
9+
void* foo(void* arg) {
10+
while (true) {
11+
printf("Hello, child thread\n");
12+
st_sleep(1);
13+
}
14+
return NULL;
15+
}
16+
17+
void* pfn(void* arg) {
18+
st_init();
19+
st_thread_create(foo, NULL, 0, 0);
20+
st_thread_exit(NULL);
21+
return NULL;
22+
}
23+
24+
int main(int argc, char** argv) {
25+
st_init();
26+
27+
pthread_t trd;
28+
pthread_create(&trd, NULL, pfn, NULL);
29+
30+
while (true) {
31+
printf("Hello, main thread\n");
32+
st_sleep(1);
33+
}
34+
return 0;
35+
}
36+

trunk/src/core/srs_core_version6.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 6
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 117
12+
#define VERSION_REVISION 118
1313

1414
#endif

0 commit comments

Comments
 (0)