-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
7 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
# !!! ST does not support C++ exceptions on cygwin !!! | ||
g++ exceptions.cpp ../../objs/st/libst.a -g -O0 -o exceptions && ./exceptions | ||
*/ | ||
#include <stdio.h> | ||
#include <exception> | ||
#include "../../objs/st/st.h" | ||
|
||
int handle_exception() { | ||
try { | ||
throw 3; | ||
} catch (...) { | ||
return 5; | ||
} | ||
} | ||
|
||
void* foo(void* arg) { | ||
int r0 = handle_exception(); | ||
printf("r0=%d\n", r0); | ||
return NULL; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
st_init(); | ||
st_thread_create(foo, NULL, 0, 0); | ||
st_thread_exit(NULL); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
g++ hello-st.cpp ../../objs/st/libst.a -g -O0 -o hello-st && ./hello-st | ||
*/ | ||
#include <stdio.h> | ||
#include "../../objs/st/st.h" | ||
|
||
void foo() { | ||
st_init(); | ||
st_sleep(1); | ||
printf("Hello World, ST!\n"); | ||
} | ||
|
||
int main() { | ||
foo(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
g++ hello-world.cpp ../../objs/st/libst.a -g -O0 -o hello-world && ./hello-world | ||
*/ | ||
#include <stdio.h> | ||
#include "../../objs/st/st.h" | ||
|
||
void foo() { | ||
st_init(); | ||
|
||
for (int i = 0; ; i++) { | ||
st_sleep(1); | ||
printf("#%d: main: working\n", i); | ||
} | ||
} | ||
|
||
int main() { | ||
foo(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
g++ hello.cpp -g -O0 -o hello && ./hello | ||
*/ | ||
|
||
void foo() { | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
foo(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
|
||
#define VERSION_MAJOR 6 | ||
#define VERSION_MINOR 0 | ||
#define VERSION_REVISION 117 | ||
#define VERSION_REVISION 118 | ||
|
||
#endif |