mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-08 22:24:25 +01:00
Improve julia_async.ipynb
This commit is contained in:
parent
71fd8cad72
commit
214dbbdf85
@ -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."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user