Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: thread_safety #22561

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

enghitalo
Copy link
Contributor

No description provided.

Comment on lines +4 to +6
v -prod -autofree ./queue.v -o ./queue.c && \
gcc ./queue.c -o ./queue.out && \
./queue.out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for that complexity.

v -prod -cc gcc ./queue.v is enough to produce a queue executable, compiled with gcc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use gcc manually you will also have to add -lpthread depending on the platform etc (it is needed on Ubuntu for example).

Using just V, it can take care of that for you.

Comment on lines +23 to +36
$if windows {
#include "@VEXEROOT/thirdparty/stdatomic/win/atomic.h"
} $else {
#include "@VEXEROOT/thirdparty/stdatomic/nix/atomic.h"
}

// Declare the atomic functions
fn C.atomic_fetch_add_u32(&u32, u32) u32
fn C.atomic_load_u32(&u32) u32

// Function to increment the atomic counter
fn increment(atomic_counter &u32) {
C.atomic_fetch_add_u32(atomic_counter, 1)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import sync as _ is enough

@spytheman spytheman merged commit 5ec9bb5 into vlang:master Oct 18, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants