- Implemented `report.nim` to create structured reports on metadata modifications. - Added functionality to merge reports and convert them to formatted strings. docs: Create prompt documentation for Markdown parser project - Added `prompt.md` detailing the requirements and functionalities for the Markdown parser. - Included specifications, usage examples, and testing guidelines. docs: Generate code review report for Markdown parser - Created `rapport_revue_code.md` outlining security vulnerabilities, code quality issues, and suggested improvements. - Provided a detailed analysis of the codebase with actionable recommendations. test: Add test data for Markdown parser - Included various Markdown files and a JPG image in `test_data` to simulate different scenarios. - Ensured that the parser can handle both valid and invalid metadata. chore: Add version management file - Created `version.nim` for automatic versioning of the Markdown parser. - Established constants for major, minor, patch, and build versions.
64 lines
1.5 KiB
Markdown
64 lines
1.5 KiB
Markdown
# La concurrence en Nim
|
|
|
|
Nim offre plusieurs mécanismes pour gérer la concurrence et le parallélisme dans vos applications. Ces fonctionnalités permettent d'exploiter efficacement les processeurs multi-cœurs modernes.
|
|
|
|
## Threads
|
|
|
|
Nim supporte les threads natifs de l'OS via le module `threads`.
|
|
|
|
```nim
|
|
import std/[threadpool]
|
|
|
|
proc processData(data: int) {.thread.} =
|
|
echo "Processing data: ", data
|
|
|
|
var threads: array[4, Thread[int]]
|
|
for i in 0..3:
|
|
createThread(threads[i], processData, i)
|
|
|
|
joinThreads(threads)
|
|
```
|
|
|
|
## ThreadPool
|
|
|
|
Pour une gestion plus simple des tâches parallèles, Nim propose le module `threadpool`.
|
|
|
|
```nim
|
|
import std/[threadpool]
|
|
|
|
proc calculateValue(x: int): int =
|
|
result = x * x
|
|
|
|
var futures = newSeq[FlowVar[int]](10)
|
|
for i in 0..9:
|
|
futures[i] = spawn calculateValue(i)
|
|
|
|
for i in 0..9:
|
|
echo ^futures[i]
|
|
```
|
|
|
|
## Async/Await
|
|
|
|
Pour la programmation asynchrone non bloquante, Nim offre le module `asyncdispatch`.
|
|
|
|
```nim
|
|
import std/[asyncdispatch, httpclient, strformat]
|
|
|
|
proc fetchUrl(url: string) {.async.} =
|
|
let client = newAsyncHttpClient()
|
|
let response = await client.get(url)
|
|
echo fmt"Fetched {url}, size: {response.body.len} bytes"
|
|
client.close()
|
|
|
|
proc main() {.async.} =
|
|
var fetches = @[
|
|
fetchUrl("https://nim-lang.org"),
|
|
fetchUrl("https://github.com/nim-lang/Nim")
|
|
]
|
|
await all(fetches)
|
|
|
|
waitFor main()
|
|
```
|
|
|
|
Ces fonctionnalités de concurrence font de Nim un excellent choix pour développer des applications hautes performances qui exploitent pleinement les capacités des processeurs modernes.
|