mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
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.
36 lines
663 B
C++
36 lines
663 B
C++
/*
|
|
Directly compile c++ source and execute:
|
|
g++ pthreads.cpp ../../objs/st/libst.a -g -O0 -o pthreads && ./pthreads
|
|
*/
|
|
#include <stdio.h>
|
|
#include <pthread.h>
|
|
#include "../../objs/st/st.h"
|
|
|
|
void* foo(void* arg) {
|
|
while (true) {
|
|
printf("Hello, child thread\n");
|
|
st_sleep(1);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void* pfn(void* arg) {
|
|
st_init();
|
|
st_thread_create(foo, NULL, 0, 0);
|
|
st_thread_exit(NULL);
|
|
return NULL;
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
st_init();
|
|
|
|
pthread_t trd;
|
|
pthread_create(&trd, NULL, pfn, NULL);
|
|
|
|
while (true) {
|
|
printf("Hello, main thread\n");
|
|
st_sleep(1);
|
|
}
|
|
return 0;
|
|
}
|
|
|