Book Image

Mastering the Nmap Scripting Engine

By : Paulino Calderon
Book Image

Mastering the Nmap Scripting Engine

By: Paulino Calderon

Overview of this book

Table of Contents (23 chapters)
Mastering the Nmap Scripting Engine
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Scan Phases
Script Categories
Nmap Options Mind Map
References
Index

Parallelism mechanisms in Lua


This section covers an interesting parallelism mechanism in Lua called coroutines that will help us achieve collaborative multitasking.

Coroutines

Coroutines in Lua are a very interesting feature that allow developers to execute multiple tasks cooperatively. Each coroutine has its own execution stack, and they are used in the background by NSE to encapsulate the execution of its scripts. The main advantage of using coroutines is the ability to suspend and yield execution of tasks. It is important to understand the difference between coroutines in Lua and traditional threads in preemptive multitasking. Coroutines share context data and, therefore, must be used to reduce overhead when working with tasks that share a lot of information. However, keep in mind that only one task is executed at any given time. Tasks must pass control among themselves to achieve collaborative multithreading.

A coroutine has three possible states:

  • Running

  • Suspended

  • Dead

Basically, the execution...