Improve julia_async.ipynb

This commit is contained in:
Noorts 2023-09-08 12:18:48 +02:00
parent 71fd8cad72
commit 214dbbdf85
No known key found for this signature in database
GPG Key ID: 49D80B7D44C852D4

View File

@ -25,7 +25,7 @@
"- Tasks\n",
"- Channels\n",
"\n",
"Understanding these concepts is important to learn later distributed computing."
"Understanding these concepts is important to learn distributed computing later."
]
},
{
@ -171,7 +171,7 @@
"id": "d483d4d0",
"metadata": {},
"source": [
"How is this possible? Tasks run in the brackground and this particular task is sleeping for most of the time. Thus, it is possible to use the current Julia process for other operations while the tasks is sleeping."
"How is this possible? Tasks run in the background and this particular task is sleeping for most of the time. Thus, it is possible to use the current Julia process for other operations while the task is sleeping."
]
},
{
@ -343,7 +343,7 @@
"source": [
"### Useful macro: `@async`\n",
"\n",
"So far, we have created tasks using low-level functions, but there are more convenient ways of creating and scheduling tasks. For instance using the `@async` macro. This macro is used to run a piece of code asynchronously. Under the hood it puts the code in an anonymous function, creates a task, and schedules it. For instance, the next cell is equivalent to previous one."
"So far, we have created tasks using low-level functions, but there are more convenient ways of creating and scheduling tasks. For instance using the `@async` macro. This macro is used to run a piece of code asynchronously. Under the hood it puts the code in an anonymous function, creates a task, and schedules it. For instance, the next cell is equivalent to the previous one."
]
},
{
@ -388,7 +388,7 @@
"\n",
"### Sending data between tasks\n",
"\n",
"Julia provides channels as a way to send data between tasks. A channel is like a FIFO queue in which tasks can put and take values from. In next example, we create a channel and a task that puts five values into the channel. Finally, the task closes the channel."
"Julia provides channels as a way to send data between tasks. A channel is like a FIFO queue which tasks can put values into and take values from. In the next example, we create a channel and a task that puts five values into the channel. Finally, the task closes the channel."
]
},
{
@ -490,7 +490,7 @@
"source": [
"### Calls to `put!` and `take!` are blocking\n",
"\n",
"Note that `put!` and `take!` are blocking operations. Calling `put!` blocks the tasks until another task calls `take!` and viceversa. Thus, we need at least 2 tasks for this to work. If we call `put!` and `take!` from the same task, it will result in a dead lock. We have added a print statement to previous example. Run it again and note how `put!` blocks until we call `take!`. "
"Note that `put!` and `take!` are blocking operations. Calling `put!` blocks the tasks until another task calls `take!` and viceversa. Thus, we need at least 2 tasks for this to work. If we call `put!` and `take!` from the same task, it will result in a dead lock. We have added a print statement to the previous example. Run it again and note how `put!` blocks until we call `take!`. "
]
},
{
@ -536,7 +536,7 @@
"source": [
"### Buffered channels\n",
"\n",
"We can be a bit more flexible and use a buffered channel. In this case, `put!` will block only if the channel is full and `take!` will block if the channel is empty. We repeat previous example, but with a buffered channel of size 2. Note that we can call `put!` until the channel is full. At this point, we need to wait to until we call `take!` which removes an item from the channel, making room for a new item."
"We can be a bit more flexible and use a buffered channel. In this case, `put!` will block only if the channel is full and `take!` will block if the channel is empty. We repeat the previous example, but with a buffered channel of size 2. Note that we can call `put!` until the channel is full. At this point, we need to wait to until we call `take!` which removes an item from the channel, making room for a new item."
]
},
{