pt-doc.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. \defgroup pt Protothreads
  3. @{
  4. Protothreads are implemented in a single header file, pt.h, which
  5. includes the local continuations header file, lc.h. This file in turn
  6. includes the actual implementation of local continuations, which
  7. typically also is contained in a single header file.
  8. */
  9. /** @} */
  10. /**
  11. \defgroup examples Examples
  12. @{
  13. \section example-small A small example
  14. This first example shows a very simple program: two protothreads
  15. waiting for each other to toggle two flags. The code illustrates how
  16. to write protothreads code, how to initialize protothreads, and how to
  17. schedule them.
  18. \include example-small.c
  19. \section example-code-lock A code-lock
  20. This example shows how to implement a simple code lock - the kind of
  21. device that is placed next to doors and that you have to push a four
  22. digit number into in order to unlock the door.
  23. The code lock waits for key presses from a numeric keyboard and if the
  24. correct code is entered, the lock is unlocked. There is a maximum time
  25. of one second between each key press, and after the correct code has
  26. been entered, no more keys must be pressed for 0.5 seconds before the
  27. lock is opened.
  28. \include example-codelock.c
  29. \section example-buffer The bounded buffer with protothread semaphores
  30. The following example shows how to implement the bounded buffer
  31. problem using the protothreads semaphore library. The example uses
  32. three protothreads: one producer() protothread that produces items,
  33. one consumer() protothread that consumes items, and one
  34. driver_thread() that schedules the producer and consumer protothreads.
  35. Note that there is no need for a mutex to guard the add_to_buffer()
  36. and get_from_buffer() functions because of the implicit locking
  37. semantics of protothreads - a protothread will never be preempted and
  38. will never block except in an explicit PT_WAIT statement.
  39. \include example-buffer.c
  40. */
  41. /** @} */