add threads dependency into meson and update readme
This commit is contained in:
parent
dc507f80dd
commit
7601680055
35
README.md
35
README.md
|
@ -45,6 +45,7 @@ There's a variety of things that set this implementation apart:
|
||||||
uses is allocated through it; that gives you complete control over its
|
uses is allocated through it; that gives you complete control over its
|
||||||
memory (for tracking, sandboxing, limits, etc.)
|
memory (for tracking, sandboxing, limits, etc.)
|
||||||
* A large degree of memory safety, with no manual management
|
* A large degree of memory safety, with no manual management
|
||||||
|
* Thread-safe by default
|
||||||
* Strings are interned, with a single reference counted instance of any
|
* Strings are interned, with a single reference counted instance of any
|
||||||
string existing at a time, which lowers memory usage and simplifies its
|
string existing at a time, which lowers memory usage and simplifies its
|
||||||
management
|
management
|
||||||
|
@ -65,7 +66,6 @@ More features and enhancements are planned, such as:
|
||||||
|
|
||||||
* Improved support for debugging information (line information tracking
|
* Improved support for debugging information (line information tracking
|
||||||
at runtime rather than just compile-time)
|
at runtime rather than just compile-time)
|
||||||
* Thread safety
|
|
||||||
|
|
||||||
Right now, the codebase is unstable, but quickly approaching production
|
Right now, the codebase is unstable, but quickly approaching production
|
||||||
readiness. You are encouraged to test things and report bugs; contributions
|
readiness. You are encouraged to test things and report bugs; contributions
|
||||||
|
@ -81,25 +81,24 @@ thread, which owns all variables and most state. Based on the main thread
|
||||||
you can create side threads, which share a lot of state with the main thread
|
you can create side threads, which share a lot of state with the main thread
|
||||||
but have their own call stack.
|
but have their own call stack.
|
||||||
|
|
||||||
In the future, accesses to "global" state (the state shared between threads)
|
These threads are not thread-safe by themselves, but as long as you ensure
|
||||||
will be made thread safe.
|
that concurrent access to them is protected, libcubescript is thread-safe,
|
||||||
|
i.e. any internal shared state between libcubescript threads is synchronized.
|
||||||
|
That means you can simply create several libcubescript threads, use them from
|
||||||
|
different OS threads, and you won't run into any trouble.
|
||||||
|
|
||||||
That means you will be able to use the library in multithreaded contexts, as
|
Additionally, this means libcubescript threads are coroutine-safe; if you
|
||||||
long as you make sure to only use any Cubescript thread from at most one
|
call into one from a coroutine and yield somewhere mid-command, you can still
|
||||||
real thread at a time (accesses to thread state will not be thread-safe).
|
access and run code on other libcubescript threads completely safely. Once
|
||||||
|
you resume the coroutine, it will continue where it left off (though global
|
||||||
|
variables may have changed).
|
||||||
|
|
||||||
Right now, this at least means the library is coroutine-safe. You can call
|
Since strings are interned and reference counted, string references returned
|
||||||
into a Cubescript thread inside a coroutine, yield somewhere mid-command,
|
by libcubescript are also safe, as you get your own reference and nothing
|
||||||
and still be able to access the state safely through other Cubescript
|
can touch it. Things taking strings will have their own references, and
|
||||||
threads. Once you resume the coroutine, it will continue where it left
|
the code will ensure that strings live for as long as a reference exists
|
||||||
off, without anything being wrong.
|
somewhere. Thanks to C++'s scoped value handling, this is mostly seamless
|
||||||
|
for the user.
|
||||||
Since strings are interned and reference counted, this is also geared
|
|
||||||
towards thread safety - any API returning a string will give you your own
|
|
||||||
reference, which means nothing can free it while you are still using it.
|
|
||||||
Similarly, things taking string references will generally increment the
|
|
||||||
count for their own purposes. This all happens automatically thanks to
|
|
||||||
C++'s scoped value handling.
|
|
||||||
|
|
||||||
## Building and usage
|
## Building and usage
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ There's a variety of things that set this implementation apart:
|
||||||
uses is allocated through it; that gives you complete control over its
|
uses is allocated through it; that gives you complete control over its
|
||||||
memory (for tracking, sandboxing, limits, etc.)
|
memory (for tracking, sandboxing, limits, etc.)
|
||||||
* A large degree of memory safety, with no manual management
|
* A large degree of memory safety, with no manual management
|
||||||
|
* Thread-safe by default
|
||||||
* Strings are interned, with a single reference counted instance of any
|
* Strings are interned, with a single reference counted instance of any
|
||||||
string existing at a time, which lowers memory usage and simplifies its
|
string existing at a time, which lowers memory usage and simplifies its
|
||||||
management
|
management
|
||||||
|
|
|
@ -49,6 +49,8 @@ endif
|
||||||
|
|
||||||
build_root = meson.current_build_dir()
|
build_root = meson.current_build_dir()
|
||||||
|
|
||||||
|
thr_dep = dependency('threads')
|
||||||
|
|
||||||
subdir('include')
|
subdir('include')
|
||||||
subdir('src')
|
subdir('src')
|
||||||
subdir('tools')
|
subdir('tools')
|
||||||
|
|
|
@ -36,11 +36,13 @@ if os_uses_dlls and get_option('default_library') == 'both'
|
||||||
# do that other than making two different targets...
|
# do that other than making two different targets...
|
||||||
libcubescript_static = static_library('cubescript',
|
libcubescript_static = static_library('cubescript',
|
||||||
libcubescript_src, include_directories: lib_incdirs,
|
libcubescript_src, include_directories: lib_incdirs,
|
||||||
|
dependencies: thr_dep,
|
||||||
cpp_args: lib_cxxflags,
|
cpp_args: lib_cxxflags,
|
||||||
install: true
|
install: true
|
||||||
)
|
)
|
||||||
libcubescript_dynamic = shared_library('cubescript',
|
libcubescript_dynamic = shared_library('cubescript',
|
||||||
libcubescript_src, include_directories: lib_incdirs,
|
libcubescript_src, include_directories: lib_incdirs,
|
||||||
|
dependencies: thr_dep,
|
||||||
cpp_args: dyn_cxxflags,
|
cpp_args: dyn_cxxflags,
|
||||||
install: true,
|
install: true,
|
||||||
version: meson.project_version()
|
version: meson.project_version()
|
||||||
|
@ -49,6 +51,7 @@ if os_uses_dlls and get_option('default_library') == 'both'
|
||||||
else
|
else
|
||||||
libcubescript_target = library('cubescript',
|
libcubescript_target = library('cubescript',
|
||||||
libcubescript_src, include_directories: lib_incdirs,
|
libcubescript_src, include_directories: lib_incdirs,
|
||||||
|
dependencies: thr_dep,
|
||||||
cpp_args: dyn_cxxflags,
|
cpp_args: dyn_cxxflags,
|
||||||
install: true,
|
install: true,
|
||||||
version: meson.project_version()
|
version: meson.project_version()
|
||||||
|
|
Loading…
Reference in a new issue