GIT.Harvie.CZ
/
mirrors
/
Programs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More strict ownership asserts
[mirrors/Programs.git]
/
c
/
pthread_extra
/
test_pause.c
diff --git
a/c/pthread_extra/test_pause.c
b/c/pthread_extra/test_pause.c
index 467328940c87c786f61b024436de2506a4fa8dc6..c12de5a36bc614ff960c862601706593dc7e1b12 100644
(file)
--- a/
c/pthread_extra/test_pause.c
+++ b/
c/pthread_extra/test_pause.c
@@
-1,3
+1,5
@@
+#define PTHREAD_FREEWHEEL
+
#include <signal.h>
#include <pthread.h>
#include <pthread_extra.h>
#include <signal.h>
#include <pthread.h>
#include <pthread_extra.h>
@@
-6,23
+8,33
@@
#include <assert.h>
#include <unistd.h>
#include <assert.h>
#include <unistd.h>
+//#define printf(...) (0)
+
+pthread_t main_thread;
+
void *thread_test(void *arg) {
//Whole process dies if you kill thread immediately before it is pausable
//pthread_pause_enable();
while(1) {
void *thread_test(void *arg) {
//Whole process dies if you kill thread immediately before it is pausable
//pthread_pause_enable();
while(1) {
- usleep(1000*300);
+ pthread_nsleep(0, 1000*1000*300);
+ pthread_pause_all();
printf("Running%s!\n", (char *)arg);
printf("Running%s!\n", (char *)arg);
+ pthread_unpause_all();
+ pthread_pause(main_thread);
+ pthread_unpause(main_thread);
}
}
int main() {
}
}
int main() {
+ main_thread = pthread_self();
+
pthread_t a, b;
pthread_pause_enable(); //Will get inherited by all threads from now on
//That way you can be sure it is pausable immediately
pthread_t a, b;
pthread_pause_enable(); //Will get inherited by all threads from now on
//That way you can be sure it is pausable immediately
- pthread_create(&a, NULL, thread_test, " A");
- pthread_create(&b, NULL, thread_test, " B");
- //sleep(1);
+ pthread_
extra_
create(&a, NULL, thread_test, " A");
+ pthread_
extra_
create(&b, NULL, thread_test, " B");
+ //
pthread_
sleep(1);
//printf("OK\n");
/*
//printf("OK\n");
/*
@@
-42,18
+54,42
@@
int main() {
while(1) {
pthread_pause(b);
pthread_unpause(a);
while(1) {
pthread_pause(b);
pthread_unpause(a);
+ pthread_pause_disable();
+ pthread_pause_disable();
+ pthread_pause_disable();
printf("SWITCH A:\n");
printf("SWITCH A:\n");
- sleep(2);
+ pthread_pause_enable();
+ pthread_pause_enable();
+ pthread_pause_enable();
+ pthread_sleep(2);
+ pthread_pause_all();
printf("SWITCH B:\n");
printf("SWITCH B:\n");
+ pthread_unpause_all();
pthread_pause(a);
pthread_unpause(b);
pthread_pause(a);
pthread_unpause(b);
- sleep(2);
+
pthread_
sleep(2);
+ //pthread_pause_disable();
+ pthread_pause_all();
printf("SWITCH A+B:\n");
printf("SWITCH A+B:\n");
+ pthread_unpause_all();
+ //pthread_pause_enable();
pthread_unpause(a);
pthread_unpause(b);
pthread_unpause(a);
pthread_unpause(b);
- sleep(1);
+ pthread_sleep(1);
+
+ //pthread_pause_disable();
+ pthread_pause_all();
+ printf("SWITCH MAIN ONLY:\n");
+ //pthread_pause_enable();
+ pthread_pause_all();
+ //printf("\n");
+ pthread_sleep(1);
+ printf("SWITCH MAIN A+B:\n");
+ pthread_unpause_all();
+ //printf("\n");
+ pthread_sleep(1);
}
pthread_join(a, NULL);
}
pthread_join(a, NULL);
This page took
0.176733 seconds
and
4
git commands to generate.