• Home
  • Raw
  • Download

Lines Matching +full:cancel +full:- +full:in +full:- +full:progress

5 way** to do *web-scale programming*? Well... no. Threads are still the medium in
21 required, signal errors directly via return values, and, as shown in the
22 :ref:`first example <thread-create-example>`, don't even require a running
29 running in one thread (the main thread)**. No other thread interacts
33 ----------------------
38 .. _thread-create-example:
40 .. rubric:: thread-create/main.c
41 .. literalinclude:: ../../code/thread-create/main.c
44 :lines: 26-36
45 :emphasize-lines: 3-7
54 custom parameters to the thread. The function ``hare`` will now run in a separate
55 thread, scheduled pre-emptively by the operating system:
57 .. rubric:: thread-create/main.c
58 .. literalinclude:: ../../code/thread-create/main.c
61 :lines: 6-14
62 :emphasize-lines: 2
66 send values use :ref:`inter-thread-communication`.
69 --------------------------
72 catalogue any surprises in the libuv APIs here. For the rest you can look at
81 .. code-block:: c
111 unlocks ``a_mutex`` but will lead to your program crashing if in debug mode, or
112 return an error in the second call to ``uv_mutex_lock()``.
121 Read-write locks are a more granular access mechanism. Two readers can access
124 holding it. Read-write locks are frequently used in databases. Here is a toy
127 .. rubric:: locks/main.c - simple rwlocks
131 :emphasize-lines: 13,16,27,31,42,55
133 Run this and observe how the readers will sometimes overlap. In case of
138 We also use barriers in the above example so that the main thread can wait for
151 In addition, libuv provides a convenience function ``uv_once()``. Multiple
181 .. _libuv-work-queue:
184 thread-local storage.
186 .. _api: http://docs.libuv.org/en/v1.x/threading.html#thread-local-storage
189 ----------------
192 a task in a separate thread, and have a callback that is triggered when the
194 tempting is that it allows potentially any third-party libraries to be used
195 with the event-loop paradigm. When you use event loops, it is *imperative to
196 make sure that no function which runs periodically in the loop thread blocks
204 own system of running the task in a separate thread. libuv just provides
208 calculate fibonacci numbers, sleeping a bit along the way, but run it in
212 .. rubric:: queue-work/main.c - lazy fibonacci
213 .. literalinclude:: ../../code/queue-work/main.c
216 :lines: 17-29
219 run in a separate thread. The ``uv_work_t`` structure is the clue. You can pass
226 .. rubric:: queue-work/main.c
227 .. literalinclude:: ../../code/queue-work/main.c
230 :lines: 31-44
231 :emphasize-lines: 10
233 The thread function will be launched in a separate thread, passed the
235 will be called on the thread the event loop is running in. It will be passed
242 available. This allows you to cancel tasks on the libuv work queue. Only tasks
254 .. rubric:: queue-cancel/main.c
255 .. literalinclude:: ../../code/queue-cancel/main.c
258 :lines: 43-
263 .. rubric:: queue-cancel/main.c
264 .. literalinclude:: ../../code/queue-cancel/main.c
267 :lines: 33-41
268 :emphasize-lines: 6
273 .. rubric:: queue-cancel/main.c
274 .. literalinclude:: ../../code/queue-cancel/main.c
277 :lines: 28-31
278 :emphasize-lines: 2
290 .. _inter-thread-communication:
292 Inter-thread communication
293 --------------------------
296 they are running. For example you might be running some long duration task in
297 a separate thread (perhaps using ``uv_queue_work``) but want to notify progress
301 .. rubric:: progress/main.c
302 .. literalinclude:: ../../code/progress/main.c
305 :lines: 7-8,35-
306 :emphasize-lines: 2,11
316 may be invoked immediately after ``uv_async_send`` is called in another
319 only guarantee that libuv makes is -- The callback function is called *at
327 .. rubric:: progress/main.c
328 .. literalinclude:: ../../code/progress/main.c
331 :lines: 10-24
332 :emphasize-lines: 7-8
334 In the download function, we modify the progress indicator and queue the message
336 non-blocking and will return immediately.
338 .. rubric:: progress/main.c
339 .. literalinclude:: ../../code/progress/main.c
342 :lines: 31-34
348 .. rubric:: progress/main.c
349 .. literalinclude:: ../../code/progress/main.c
352 :lines: 26-29
353 :emphasize-lines: 3
358 a mutex or rwlock to ensure accesses are performed in the right order.
366 libraries that require thread affinity for their functionality. For example in
368 that the v8 instance was started in. Interacting with v8 data structures from
372 1. In node, the third party library is set up with a JavaScript callback to be
377 console.log("Progress");
384 2. ``lib.do`` is supposed to be non-blocking but the third party lib is
387 3. The actual work being done in a separate thread wants to invoke the progress
391 4. The async callback, invoked in the main loop thread, which is the v8 thread,
394 ----
396 .. _node.js is cancer: http://widgetsandshit.com/teddziuba/2011/10/node-js-is-cancer.html