atomic_int x[2], idx, y;
-int r1, r2, r3; /* "local" variables */
+int r1, r2, r3; /* "local" variables */
static void a(void *obj)
{
static void a(void *obj)
{
-
+
m->lock();
while(load_32(&shareddata)==0)
v->wait(*m);
atomic_int x, y;
atomic_intptr_t z, z2;
-int r1, r2, r3; /* "local" variables */
+int r1, r2, r3; /* "local" variables */
/**
- This example illustrates a self-satisfying cycle involving
- synchronization. A failed synchronization creates the store that
- causes the synchronization to fail.
+ This example illustrates a self-satisfying cycle involving
+ synchronization. A failed synchronization creates the store that
+ causes the synchronization to fail.
- The C++11 memory model nominally allows r1=0, r2=1, r3=5.
+ The C++11 memory model nominally allows r1=0, r2=1, r3=5.
- This example is insane, we don't support that behavior.
-*/
+ This example is insane, we don't support that behavior.
+ */
static void a(void *obj)
using namespace std;
atomic_int x, y;
-int r1, r2, r3, r4; /* "local" variables */
+int r1, r2, r3, r4; /* "local" variables */
static void a(void *obj)
{
using namespace std;
atomic_int x, y;
-int r1, r2, r3, r4; /* "local" variables */
+int r1, r2, r3, r4; /* "local" variables */
static void a(void *obj)
{
static void a(void *obj)
{
int i;
- for(i = 0; i < 2; i++) {
+ for(i = 0;i < 2;i++) {
if ((i % 2) == 0) {
read_lock(&mylock);
load_32(&shareddata);
static void a(void *obj)
{
int i;
- for(i = 0; i < 2; i++) {
+ for(i = 0;i < 2;i++) {
if ((i % 2) == 0) {
read_lock(&mylock);
load_32(&shareddata);
using namespace std;
atomic_int x, y;
-int r0, r1, r2, r3; /* "local" variables */
+int r0, r1, r2, r3; /* "local" variables */
static void a(void *obj)
{
atomic_int z;
static void a(void *obj)
{
- (void)atomic_load_explicit(&z, memory_order_relaxed); // this is only for schedule control
+ (void)atomic_load_explicit(&z, memory_order_relaxed); // this is only for schedule control
int t1=atomic_load_explicit(&x, memory_order_relaxed);
atomic_store_explicit(&y, 1, memory_order_relaxed);
printf("t1=%d\n",t1);
printf("expected: %d\n", expected);
/*
short v1 = atomic_exchange_explicit(&x, 8, memory_order_relaxed);
- short v2 = atomic_exchange_explicit(&x, -10, memory_order_relaxed);
- short v3 = atomic_load_explicit(&x, memory_order_relaxed);
- printf("v1 = %d, v2 = %d, v3 = %d\n", v1, v2, v3);
-*/
+ short v2 = atomic_exchange_explicit(&x, -10, memory_order_relaxed);
+ short v3 = atomic_load_explicit(&x, memory_order_relaxed);
+ printf("v1 = %d, v2 = %d, v3 = %d\n", v1, v2, v3);
+ */
}
static void b(void *obj)
static void a(void *obj)
{
int i;
- for (i = 0; i < N; i++)
+ for (i = 0;i < N;i++)
atomic_fetch_add_explicit(&x, 1, memory_order_relaxed);
}
#include <threads.h>
#include <stdatomic.h>
#include "librace.h"
- atomic_int x1;
- atomic_int x2;
- atomic_int x3;
- atomic_int x4;
- atomic_int x5;
- atomic_int x6;
- atomic_int x7;
+atomic_int x1;
+atomic_int x2;
+atomic_int x3;
+atomic_int x4;
+atomic_int x5;
+atomic_int x6;
+atomic_int x7;
static void a(void *obj)
{
atomic_store_explicit(&x1, 1,memory_order_relaxed);
int user_main(int argc, char **argv)
{
thrd_t t1, t2, t3, t4, t5, t6, t7, t8;
- atomic_init(&x1, 0);
- atomic_init(&x2, 0);
- atomic_init(&x3, 0);
- atomic_init(&x4, 0);
- atomic_init(&x5, 0);
- atomic_init(&x6, 0);
- atomic_init(&x7, 0);
+ atomic_init(&x1, 0);
+ atomic_init(&x2, 0);
+ atomic_init(&x3, 0);
+ atomic_init(&x4, 0);
+ atomic_init(&x5, 0);
+ atomic_init(&x6, 0);
+ atomic_init(&x7, 0);
- thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&b, NULL);
- thrd_create(&t3, (thrd_start_t)&c, NULL);
- thrd_create(&t4, (thrd_start_t)&d, NULL);
- thrd_create(&t5, (thrd_start_t)&e, NULL);
- thrd_create(&t6, (thrd_start_t)&f, NULL);
- thrd_create(&t7, (thrd_start_t)&g, NULL);
- thrd_create(&t8, (thrd_start_t)&h, NULL);
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+ thrd_create(&t3, (thrd_start_t)&c, NULL);
+ thrd_create(&t4, (thrd_start_t)&d, NULL);
+ thrd_create(&t5, (thrd_start_t)&e, NULL);
+ thrd_create(&t6, (thrd_start_t)&f, NULL);
+ thrd_create(&t7, (thrd_start_t)&g, NULL);
+ thrd_create(&t8, (thrd_start_t)&h, NULL);
- thrd_join(t1);
- thrd_join(t2);
- thrd_join(t3);
- thrd_join(t4);
- thrd_join(t5);
- thrd_join(t6);
- thrd_join(t7);
- thrd_join(t8);
+ thrd_join(t1);
+ thrd_join(t2);
+ thrd_join(t3);
+ thrd_join(t4);
+ thrd_join(t5);
+ thrd_join(t6);
+ thrd_join(t7);
+ thrd_join(t8);
- return 0;
+ return 0;
}
#include <threads.h>
#include <stdatomic.h>
#include "librace.h"
- atomic_int x1;
- atomic_int x2;
- atomic_int x3;
- atomic_int x4;
- atomic_int x5;
- atomic_int x6;
- atomic_int x7;
+atomic_int x1;
+atomic_int x2;
+atomic_int x3;
+atomic_int x4;
+atomic_int x5;
+atomic_int x6;
+atomic_int x7;
static void a(void *obj)
{
atomic_store_explicit(&x1, 1,memory_order_seq_cst);
int user_main(int argc, char **argv)
{
thrd_t t1, t2, t3, t4, t5, t6, t7, t8;
- atomic_init(&x1, 0);
- atomic_init(&x2, 0);
- atomic_init(&x3, 0);
- atomic_init(&x4, 0);
- atomic_init(&x5, 0);
- atomic_init(&x6, 0);
- atomic_init(&x7, 0);
+ atomic_init(&x1, 0);
+ atomic_init(&x2, 0);
+ atomic_init(&x3, 0);
+ atomic_init(&x4, 0);
+ atomic_init(&x5, 0);
+ atomic_init(&x6, 0);
+ atomic_init(&x7, 0);
- thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&b, NULL);
- thrd_create(&t3, (thrd_start_t)&c, NULL);
- thrd_create(&t4, (thrd_start_t)&d, NULL);
- thrd_create(&t5, (thrd_start_t)&e, NULL);
- thrd_create(&t6, (thrd_start_t)&f, NULL);
- thrd_create(&t7, (thrd_start_t)&g, NULL);
- thrd_create(&t8, (thrd_start_t)&h, NULL);
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+ thrd_create(&t3, (thrd_start_t)&c, NULL);
+ thrd_create(&t4, (thrd_start_t)&d, NULL);
+ thrd_create(&t5, (thrd_start_t)&e, NULL);
+ thrd_create(&t6, (thrd_start_t)&f, NULL);
+ thrd_create(&t7, (thrd_start_t)&g, NULL);
+ thrd_create(&t8, (thrd_start_t)&h, NULL);
- thrd_join(t1);
- thrd_join(t2);
- thrd_join(t3);
- thrd_join(t4);
- thrd_join(t5);
- thrd_join(t6);
- thrd_join(t7);
- thrd_join(t8);
+ thrd_join(t1);
+ thrd_join(t2);
+ thrd_join(t3);
+ thrd_join(t4);
+ thrd_join(t5);
+ thrd_join(t6);
+ thrd_join(t7);
+ thrd_join(t8);
- return 0;
+ return 0;
}