summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-26 11:08:57 +0100
committerTyge Løvset <[email protected]>2021-11-26 11:08:57 +0100
commitcde7c39de3492f8b701038af6563a6c4e01ff558 (patch)
tree55529f503a0925b185ccc42f3a9cad20de9a2821 /examples
parentf857d8215a266673e25356779f740100fe362025 (diff)
downloadSTC-modified-cde7c39de3492f8b701038af6563a6c4e01ff558.tar.gz
STC-modified-cde7c39de3492f8b701038af6563a6c4e01ff558.zip
Bugfix of c_atomic_decrement() asm version in csptr.h. Some cleanup
Diffstat (limited to 'examples')
-rw-r--r--examples/random.c4
-rw-r--r--examples/read.c6
-rw-r--r--examples/sptr_pthread.c8
3 files changed, 9 insertions, 9 deletions
diff --git a/examples/random.c b/examples/random.c
index d4a12a27..81fe71c5 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -4,7 +4,7 @@
int main()
{
- const size_t N = 5000000000;
+ const size_t N = 1000000000;
const uint64_t seed = time(NULL), range = 1000000;
stc64_t rng = stc64_init(seed);
@@ -39,4 +39,4 @@ int main()
diff = clock() - before;
printf("biased 0-%zu \t: %f secs, %zu, avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
-} \ No newline at end of file
+}
diff --git a/examples/read.c b/examples/read.c
index 728bf579..4e670a10 100644
--- a/examples/read.c
+++ b/examples/read.c
@@ -6,9 +6,9 @@ cvec_str read_file(const char* name)
{
cvec_str vec = cvec_str_init();
c_autovar (FILE* f = fopen(name, "r"), fclose(f))
- c_auto (cstr, line)
- while (cstr_getline(&line, f))
- cvec_str_emplace_back(&vec, line.str);
+ c_autovar (cstr line = cstr_init(), cstr_del(&line))
+ while (cstr_getline(&line, f))
+ cvec_str_emplace_back(&vec, line.str);
return vec;
}
diff --git a/examples/sptr_pthread.c b/examples/sptr_pthread.c
index 63b9a7a4..cffafd3d 100644
--- a/examples/sptr_pthread.c
+++ b/examples/sptr_pthread.c
@@ -25,7 +25,7 @@ void* thr(csptr_base* lp)
c_autoscope (pthread_mutex_lock(&mtx), pthread_mutex_unlock(&mtx))
{
printf("local pointer in a thread:\n"
- " p.get() = %p, p.use_count() = %zu\n", (void*)lp->get, *lp->use_count);
+ " p.get() = %p, p.use_count() = %ld\n", (void*)lp->get, *lp->use_count);
}
/* atomically decrease ref. */
csptr_base_del(lp);
@@ -37,7 +37,7 @@ int main()
csptr_base p = csptr_base_make((Base){42});
printf("Created a Base\n"
- " p.get() = %p, p.use_count() = %zu\n", (void*)p.get, *p.use_count);
+ " p.get() = %p, p.use_count() = %ld\n", (void*)p.get, *p.use_count);
enum {N = 3};
pthread_t t[N];
csptr_base c[N];
@@ -48,7 +48,7 @@ int main()
printf("Shared ownership between %d threads and released\n"
"ownership from main:\n"
- " p.get() = %p, p.use_count() = %zu\n", N, (void*)p.get, *p.use_count);
+ " p.get() = %p, p.use_count() = %ld\n", N, (void*)p.get, *p.use_count);
csptr_base_reset(&p);
c_forrange (i, N) pthread_join(t[i], NULL);
@@ -57,4 +57,4 @@ int main()
#else
int main() {}
-#endif \ No newline at end of file
+#endif