diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-31 02:11:03 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-31 02:11:03 -0400 |
| commit | 7a172be6213839a3d023ba21c3bafd7540a4bfe8 (patch) | |
| tree | 5646ba0e4c0690fe64711fb77658308541de695b /docs | |
| parent | d3655740cc6a8e6c4788946af412065fb52f51dc (diff) | |
Remove threads and mutexed data from the language in favor of a
module-based approach
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 2 | ||||
| -rw-r--r-- | docs/mutexed.md | 34 | ||||
| -rw-r--r-- | docs/serialization.md | 7 | ||||
| -rw-r--r-- | docs/threads.md | 93 |
4 files changed, 3 insertions, 133 deletions
diff --git a/docs/README.md b/docs/README.md index 0034ab8b..f7884321 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,7 +25,6 @@ Information about Tomo's built-in types can be found here: - [Floating point numbers](nums.md) - [Integers](integers.md) - [Languages](langs.md) -- [Mutexed Data](mutexed.md) - [Paths](paths.md) - [Random Number Generators](rng.md) - [Sets](sets.md) @@ -33,7 +32,6 @@ Information about Tomo's built-in types can be found here: - [Tables](tables.md) - [Text](text.md) - [Text Pattern Matching](patterns.md) -- [Threads](threads.md) ## Built-in Functions diff --git a/docs/mutexed.md b/docs/mutexed.md deleted file mode 100644 index 97357f39..00000000 --- a/docs/mutexed.md +++ /dev/null @@ -1,34 +0,0 @@ -# Mutexed Data - -To serve the general case of synchronizing access to shared datastructures, -Tomo uses the `mutexed` keyword, which allocates a mutex and some heap memory -for a value. Access to the heap-allocated value's memory can only be obtained -by using a `holding` block. `holding` blocks ensure that the underlying mutex -is locked before entering the block and unlocked before leaving it (even if a -short-circuiting control flow statement like `return` or `stop` is used). Here -is a simple example: - -```tomo -nums := mutexed [10, 20, 30] - ->> nums -= mutexed [Int]<0x12345678> : mutexed([Int]) - -holding nums: - # Inside this block, the type of `nums` is `&[Int]` - >> nums - = &[10, 20, 30] : &[Int] - -thread := Thread.new(func(): - holding nums: - nums:insert(30) -) - -holding nums: - nums:insert(40) - -thread:join() -``` - -Without using a mutex, the code above could run into concurrency issues leading -to data corruption. diff --git a/docs/serialization.md b/docs/serialization.md index 764a6b27..0f158be1 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -70,7 +70,6 @@ only 9 bytes for the whole thing! ## Unserializable Types -Unfortunately, not all types can be easily serialized. In particular, -`Thread`s, types, and functions cannot be serialized because their data -contents cannot be easily converted to portable byte arrays. All other -datatypes _can_ be serialized. +Unfortunately, not all types can be easily serialized. In particular, types and +functions cannot be serialized because their data contents cannot be easily +converted to portable byte arrays. All other datatypes _can_ be serialized. diff --git a/docs/threads.md b/docs/threads.md deleted file mode 100644 index 3bd2dd0f..00000000 --- a/docs/threads.md +++ /dev/null @@ -1,93 +0,0 @@ -# Threads - -Tomo supports POSIX threads (pthreads) through the `Thread` type. The -recommended practice is to have each thread interact with other threads only -through [mutex-guarded datastructures](mutexed.md). - -## Thread Methods - -- [`func cancel(thread: Thread)`](#cancel) -- [`func detach(thread: Thread)`](#detach) -- [`func join(thread: Thread)`](#join) -- [`func new(fn: func(->Void) -> Thread)`](#new) - -### `cancel` -Requests the cancellation of a specified thread. - -```tomo -func cancel(thread: Thread) -``` - -- `thread`: The thread to cancel. - -**Returns:** -Nothing. - -**Example:** -```tomo ->> thread:cancel() -``` - ---- - -### `detach` -Detaches a specified thread, allowing it to run independently. - -```tomo -func detach(thread: Thread) -``` - -- `thread`: The thread to detach. - -**Returns:** -Nothing. - -**Example:** -```tomo ->> thread:detach() -``` -### `join` -Waits for a specified thread to terminate. - -```tomo -func join(thread: Thread) -``` - -- `thread`: The thread to join. - -**Returns:** -Nothing. - -**Example:** -```tomo ->> thread:join() -``` - ---- - -### `new` -Creates a new thread to execute a specified function. - -```tomo -func new(fn: func(->Void) -> Thread) -``` - -- `fn`: The function to be executed by the new thread. - -**Returns:** -A new `Thread` object representing the created thread. - -**Example:** -```tomo ->> jobs := |Int| ->> results := |Int| ->> thread := Thread.new(func(): - repeat: - input := jobs:get() - results:give(input + 10 -) -= Thread<0x12345678> ->> jobs:give(10) ->> results:get() -= 11 -``` |
