Skip to content

Commit 55362f6

Browse files
committed
Improve explanation for the usage of sched_yield
Because calling `sched_yield` does not guarantee that a different thread will be switched to.
1 parent 8c8ad9b commit 55362f6

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

regression/cbmc-sequentialization/pthread_mutex/no_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void *worker(void *arguments)
1212
for(int i = 0; i < 100; ++i)
1313
{
1414
int shared_count_copy = shared_count;
15-
// The following call to yield is here in order to cause a thread swap
16-
// during concrete execution in order to demonstrate unsoundness.
15+
// The following call to yield is here in order to increase the chance of
16+
// thread swaps during concrete execution in order to show unsoundness.
1717
sched_yield();
1818
++shared_count_copy;
1919
shared_count = shared_count_copy;

regression/cbmc-sequentialization/pthread_mutex/with_mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void *worker(void *arguments)
1515
const int lock_error = pthread_mutex_lock(&mutex);
1616
assert(!lock_error);
1717
int shared_count_copy = shared_count;
18-
// The following call to yield is here in order to cause a thread swap
19-
// during concrete execution in order to demonstrate unsoundness.
18+
// The following call to yield is here in order to increase the chance of
19+
// thread swaps during concrete execution in order to show unsoundness.
2020
sched_yield();
2121
++shared_count_copy;
2222
shared_count = shared_count_copy;

regression/cbmc-sequentialization/rw_lock/with_lock.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ void set_state1(struct sharedt *shared)
1919
{
2020
shared->a = 1;
2121
shared->b = 2;
22-
// The following call to yield causes a thread switch during concrete
23-
// execution in order to demonstrate unsoundness without locks.
22+
// The following call to yield is here in order to increase the chance of
23+
// thread swaps during concrete execution in order to show unsoundness.
2424
sched_yield();
2525
shared->c = 3;
2626
}
@@ -29,8 +29,8 @@ void set_state2(struct sharedt *shared)
2929
{
3030
shared->a = 4;
3131
shared->b = 5;
32-
// The following call to yield causes a thread switch during concrete
33-
// execution in order to demonstrate unsoundness without locks.
32+
// The following call to yield is here in order to increase the chance of
33+
// thread swaps during concrete execution in order to show unsoundness.
3434
sched_yield();
3535
shared->c = 6;
3636
}
@@ -81,8 +81,8 @@ void *checker(void *arguments)
8181
assert(!lock_error);
8282
#endif
8383
const bool is_state1 = shared->a == 1 && shared->b == 2 && shared->c == 3;
84-
// The following call to yield causes a thread switch during concrete
85-
// execution in order to demonstrate unsoundness without locks.
84+
// The following call to yield is here in order to increase the chance of
85+
// thread swaps during concrete execution in order to show unsoundness.
8686
sched_yield();
8787
const bool is_state2 = shared->a == 4 && shared->b == 5 && shared->c == 6;
8888
assert(is_state1 != is_state2);

0 commit comments

Comments
 (0)