<commit_before>#Getting started with rethread
This tutorial is written for rethread without exceptions.

`rethread` is all about cancelling functions. Long or blocking functions receive `cancellation_token` from caller. Such a function should:
* Check the token state periodically
* Return if higher-level code cancels token
* Pass it to other long or blocking functions

If a blocking function doesn't support `cancellation_token`, there are two options:
1. If the function blocks because of `condition_variable`, `this_thread::sleep` or a simple busy-loop - it has to be reimplemented to add cancellation support
2. If the function blocks in some other call - it is necessary to write proper `cancellation_handler` and set up proper wake-up mechanism

This guide covers option 1. Advanced guide about writing custom cancellation handlers can be found [here TODO:write advanced guide].

##Writing cancellable functions
Adding cancellability to the blocking function involves several steps:
* Adjust return value
* Add cancellation_token parameter
* Reimplement blocking parts
* Add dummy_cancellation_token if necessary

Let's add cancellation support to the `pop` method of the following `concurrent_queue` class:
```cpp
template <typename T><commit_msg>Fixed list formatting in Primer<commit_after>#Getting started with rethread
This tutorial is written for rethread without exceptions.

`rethread` is all about cancelling functions. Long or blocking functions receive `cancellation_token` from caller. Such a function should:
* Check the token state periodically
* Return if higher-level code cancels token
* Pass it to other long or blocking functions

If a blocking function doesn't support `cancellation_token`, there are two options:

1. If the function blocks because of `condition_variable`, `this_thread::sleep` or a simple busy-loop - it has to be reimplemented to add cancellation support
2. If the function blocks in some other call - it is necessary to write proper `cancellation_handler` and set up proper wake-up mechanism

This guide covers option 1. Advanced guide about writing custom cancellation handlers can be found [here TODO:write advanced guide].

##Writing cancellable functions
Adding cancellability to the blocking function involves several steps:
* Adjust return value
* Add cancellation_token parameter
* Reimplement blocking parts
* Add dummy_cancellation_token if necessary

Let's add cancellation support to the `pop` method of the following `concurrent_queue` class:
```cpp
template <typename T>
{'fraction_non_alphanumeric': 0.046621888581588306, 'fraction_numerical': 0.002370604504148558, 'mean_word_length': 5.5595854922279795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '294319', 'n_tokens_mistral': 603, 'n_tokens_neox': 580, 'n_words': 333}