<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: The Polymorphic Guy</title>
    <description>The latest articles on DEV Community by The Polymorphic Guy (@polymorphicguy).</description>
    <link>https://dev.to/polymorphicguy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F25419%2Fca04585c-8d96-44ed-a064-2d2fa48c3ac6.png</url>
      <title>DEV Community: The Polymorphic Guy</title>
      <link>https://dev.to/polymorphicguy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/polymorphicguy"/>
    <language>en</language>
    <item>
      <title>The Most Used Java Frameworks Nowadays (2026)</title>
      <dc:creator>The Polymorphic Guy</dc:creator>
      <pubDate>Tue, 24 Feb 2026 01:20:02 +0000</pubDate>
      <link>https://dev.to/polymorphicguy/the-most-used-java-frameworks-nowadays-2026-1g44</link>
      <guid>https://dev.to/polymorphicguy/the-most-used-java-frameworks-nowadays-2026-1g44</guid>
      <description>&lt;p&gt;In the modern Java ecosystem, some frameworks stand out for their broad adoption, community support, and real usage in production applications today. This list reflects what developers and teams are actually using in 2026 — based on recent trends and industry reporting — rather than historical or legacy frameworks. Below I’ve gathered a list and videos that I’ve watched and found very informative about each framework.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;a href="https://spring.io/" rel="noopener noreferrer"&gt;Spring Boot&lt;/a&gt; — The Enterprise Standard
&lt;/h2&gt;

&lt;p&gt;No conversation about Java frameworks is complete without Spring Boot.&lt;/p&gt;

&lt;p&gt;Spring Boot remains the most popular Java framework in 2026, thanks to its mature ecosystem, excellent documentation, and wide adoption for building REST APIs, microservices, and large enterprise backends. It has an extensive extension ecosystem (Spring Security, Spring Cloud, Spring Data) that makes it a default choice for many teams.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/gJrjgg1KVL4"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://quarkus.io/" rel="noopener noreferrer"&gt;Quarkus&lt;/a&gt; — The Cloud-Native Challenger
&lt;/h2&gt;

&lt;p&gt;Quarkus has become one of the most talked-about frameworks for cloud-native applications.&lt;/p&gt;

&lt;p&gt;Designed from the ground up for Kubernetes and GraalVM, Quarkus delivers extremely fast startup times and low memory consumption. Teams building containerized microservices and serverless workloads are increasingly turning to it.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/JfEnYZoJu1s"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://micronaut.io/" rel="noopener noreferrer"&gt;Micronaut&lt;/a&gt; — Lightweight and Fast
&lt;/h2&gt;

&lt;p&gt;Micronaut continues to grow as a framework focused on performance and efficiency.&lt;/p&gt;

&lt;p&gt;Its design avoids heavy runtime reflection, resulting in a smaller memory footprint. It’s especially popular in serverless functions and edge environments, where startup speed and efficiency matter.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/nYVLbLhuh64"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://jakarta.ee/" rel="noopener noreferrer"&gt;Jakarta EE&lt;/a&gt; — Standards-Based Enterprise
&lt;/h2&gt;

&lt;p&gt;Jakarta EE (the successor to Java EE) remains relevant in 2026.&lt;/p&gt;

&lt;p&gt;It serves as a standards-based foundation for enterprise applications and is still widely used in regulated industries where standardized specifications are preferred over proprietary frameworks.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/AJxBg90HM4s"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;a href="https://hibernate.org/" rel="noopener noreferrer"&gt;Hibernate&lt;/a&gt; — The Persistence Layer Everyone Uses
&lt;/h2&gt;

&lt;p&gt;Although not a web framework, Hibernate is one of the most widely used Java frameworks for object-relational mapping (ORM).&lt;/p&gt;

&lt;p&gt;It simplifies database interactions and is commonly paired with other frameworks like Spring Boot, Quarkus, and Micronaut.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/xHminZ9Dxm4"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;a href="https://vaadin.com/" rel="noopener noreferrer"&gt;Vaadin&lt;/a&gt; — Full-Stack Web UI in Java
&lt;/h2&gt;

&lt;p&gt;Vaadin stands out as one of the few frameworks that lets you build full web UIs purely in Java, without writing JavaScript.&lt;/p&gt;

&lt;p&gt;It’s often chosen for business applications, dashboards, and internal tools by teams who want to keep front-end and back-end in the same language.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/YDzz6xJ8Sds"&gt;
  &lt;/iframe&gt;


&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;In the present day, the Java framework ecosystem remains vibrant and relevant. Spring Boot continues to lead in adoption and community size, with cloud-native options like Quarkus and Micronaut gaining traction, Jakarta EE still serving enterprise standards, Hibernate remaining the dominant ORM, and Vaadin providing a full-stack Java UI option across different types of projects.&lt;/p&gt;

&lt;p&gt;This list reflects frameworks that are actively used today, based on current ecosystem trends and industry reporting — not merely legacy popularity.&lt;/p&gt;

&lt;p&gt;Let’s connect!&lt;br&gt;
&lt;a href="https://github.com/higher-order-programmer" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/caduolivieri/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>The 11 Most Popular NuGet Packages to Know in 2026 (updated!)</title>
      <dc:creator>The Polymorphic Guy</dc:creator>
      <pubDate>Sat, 21 Feb 2026 18:11:48 +0000</pubDate>
      <link>https://dev.to/polymorphicguy/the-11-most-popular-nuget-packages-to-know-in-2026-updated-20f5</link>
      <guid>https://dev.to/polymorphicguy/the-11-most-popular-nuget-packages-to-know-in-2026-updated-20f5</guid>
      <description>&lt;p&gt;In the .NET ecosystem, NuGet remains the primary package manager for dependencies — and some libraries continue to dominate because they solve core development challenges efficiently. Below, I show you the most widely adopted and high-impact packages as of 2026, backed by download statistics from the official NuGet.org registry.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;a href="https://www.nuget.org/packages/Newtonsoft.Json/13.0.5-beta1" rel="noopener noreferrer"&gt;Newtonsoft.Json&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Newtonsoft.Json has long been the go-to JSON serializer for .NET applications. It handles complex serialization and deserialization scenarios with ease and is still the most downloaded NuGet package overall, boasting hundreds of millions of downloads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Nearly every .NET project deals with JSON data — from APIs to configuration — and Newtonsoft.Json remains reliable when performance and flexibility matter.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;a href="https://www.nuget.org/packages/Serilog/4.3.2-dev-02418" rel="noopener noreferrer"&gt;Serilog&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Serilog is a structured logging library that has become a de-facto standard in .NET. It supports sinks for writing structured logs to files, consoles, and remote systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Applications today need rich, searchable logs to diagnose issues in production, especially in distributed or cloud environments.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://www.nuget.org/packages/Polly" rel="noopener noreferrer"&gt;Polly&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Polly provides a comprehensive resilience framework for transient fault handling, including retry, circuit breaker, timeout, and fallback policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: As .NET apps increasingly interact with remote services, built-in resilience becomes essential to avoid cascading failures.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://www.nuget.org/packages/CsvHelper" rel="noopener noreferrer"&gt;CsvHelper&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;CsvHelper is a fast and flexible library for reading and writing CSV data. It’s ideal for data import/export tasks and lightweight ETL workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: CSV remains a ubiquitous format for data exchange across systems — and CsvHelper simplifies working with it in .NET.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;a href="https://www.nuget.org/packages/Swashbuckle.AspNetCore" rel="noopener noreferrer"&gt;Swashbuckle.AspNetCore&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This library integrates Swagger/OpenAPI into ASP.NET Core applications, enabling automatic API documentation generation and interactive UI at runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Clear, self-documenting APIs are critical for developer productivity and external integrations.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;a href="https://www.nuget.org/packages/AWSSDK.Polly" rel="noopener noreferrer"&gt;awssdk.polly&lt;/a&gt; &amp;amp; &lt;a href="https://www.nuget.org/packages/AWSSDK.Core" rel="noopener noreferrer"&gt;awssdk.core&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The AWS SDK packages — including awssdk.polly and awssdk.core — appear among the highest download counts, reflecting widespread use of AWS services from .NET applications.&lt;/p&gt;

&lt;p&gt;Why it matters: Integration with cloud services like AWS remains a major use case for enterprise and startup .NET workloads.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;a href="https://www.nuget.org/packages/Google.Protobuf/3.34.0-rc2" rel="noopener noreferrer"&gt;Google.Protobuf&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Google.Protobuf provides support for Protocol Buffers, a compact data serialization format widely used for high-performance communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Protocol Buffers are popular in microservices and gRPC scenarios, where efficiency and strong typing matter.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. &lt;a href="https://www.nuget.org/packages/Ecng.Collections" rel="noopener noreferrer"&gt;Ecng.Collections&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Ecng.Collections is a high-performance collection library that offers advanced structures beyond the standard .NET collections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Many large-scale and performance-sensitive applications adopt specialized collections to optimize memory and speed.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  9. &lt;a href="https://www.nuget.org/packages/xunit.v3/" rel="noopener noreferrer"&gt;Xunit&lt;/a&gt; &amp;amp; &lt;a href="https://www.nuget.org/packages/Moq" rel="noopener noreferrer"&gt;Moq&lt;/a&gt; (Test &amp;amp; Mocking Tools)
&lt;/h2&gt;

&lt;p&gt;Testing libraries like xUnit and mocking frameworks like Moq aren’t always in the top aggregate download list from NuGet.org, but community sources point to them as indispensable development tools.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Unit testing and mocking accelerate development quality and confidence as .NET projects scale.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  10. &lt;a href="https://www.nuget.org/packages/Dapper" rel="noopener noreferrer"&gt;Dapper&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Dapper is a lightweight, high-performance micro-ORM for .NET that extends the ADO.NET IDbConnection interface to provide simple methods for executing SQL queries and mapping results to .NET objects. It’s widely appreciated for its speed — nearly as fast as raw ADO.NET — and is ideal in scenarios where performance and control over SQL matter most, such as high-throughput APIs and complex reporting queries. Its simplicity and minimal abstraction make it a popular choice when developers want to avoid the overhead of a full ORM while still benefiting from object mapping.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Dapper streamlines data access with minimal overhead.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  11. &lt;a href="https://www.nuget.org/packages/AutoMapper" rel="noopener noreferrer"&gt;AutoMapper&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;AutoMapper is a convention-based object-object mapping library that automates the process of copying data between different types of objects, like transforming domain models into DTOs and vice versa. Rather than manually assigning each property, AutoMapper lets developers define mapping configurations once and reuse them throughout the codebase, reducing boilerplate and improving readability. It remains popular in many projects for handling repetitive mapping logic, especially in applications with many model transformations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: AutoMapper reduces boilerplate when copying data between domain models and DTOs.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why These Matter for 2026&lt;br&gt;&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Modern Architecture&lt;/strong&gt;: Patterns like resilience (Polly), clean validation (FluentValidation), and decoupled logic (MediatR) are increasingly standard as .NET apps scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer Tooling&lt;/strong&gt;: Serilog, Swashbuckle, and Bogus enhance productivity in logging, API documentation, and testing, respectively.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Trends Shaping NuGet Usage in 2026&lt;br&gt;&lt;br&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resilience &amp;amp; Reliability&lt;/strong&gt;: Packages like Polly show the growing emphasis on robust, fault-tolerant systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Integration&lt;/strong&gt;: Adoption of AWS and Google libraries reflects the shift toward cloud-native architectures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Developer Productivity&lt;/strong&gt;: Tools for logging (Serilog), documentation (Swashbuckle), testing (xUnit/Moq), and mapping (AutoMapper) remain core to efficient workflows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Focus&lt;/strong&gt;: Libraries like Dapper and Ecng.Collections are preferred when performance matters most.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, these are the top 11 NuGet packages shaping .NET development in 2026. Whether you are a new or experienced .NET developer, these libraries reflect the current ecosystem’s priorities — from JSON handling and resilience to structured logging, API documentation, and high-performance data access. Choosing the right packages can help you write more robust, maintainable, and efficient code, and staying aware of trends keeps your projects up to date with modern .NET practices backed by real-world usage data.&lt;/p&gt;

&lt;p&gt;Let’s connect!&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/higher-order-programmer" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/caduolivieri/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>programming</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Modern C++: Multithreading and Filesystem library (practical example)</title>
      <dc:creator>The Polymorphic Guy</dc:creator>
      <pubDate>Thu, 09 Apr 2020 22:09:48 +0000</pubDate>
      <link>https://dev.to/polymorphicguy/modern-c-multithreading-and-filesystem-library-practical-example-51l5</link>
      <guid>https://dev.to/polymorphicguy/modern-c-multithreading-and-filesystem-library-practical-example-51l5</guid>
      <description>&lt;p&gt;In this post, I will show you a bit of usage of multithreaded programming (C++11) and the Filesystem library (C++ 17). The idea is to get straight to the point.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: This is just a hypothetical approach that simulates a timer to check for any new files in a directory at regular intervals. The recommended approach for the real scenario would be to use some API from the OS itself (such as &lt;a href="http://man7.org/linux/man-pages/man7/inotify.7.html" rel="noopener noreferrer"&gt;inotify&lt;/a&gt; on Linux) that notifies processes when a file system event occurs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Definitions:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//dirmgr.hpp&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="mi"&gt;3&lt;/span&gt;  &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;4&lt;/span&gt;  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DirManager&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;      &lt;span class="k"&gt;private&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;          &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;watching_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;          &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;stop_flag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;          &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;         &lt;span class="kr"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;obj_linked_thd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;11&lt;/span&gt;      &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mi"&gt;12&lt;/span&gt;          &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;13&lt;/span&gt;          &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;check_dirs&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;14&lt;/span&gt;          &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;start_watching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;15&lt;/span&gt;          &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;stop_watching&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;16&lt;/span&gt;  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;First of all, I defined a class (DirManager), which will fulfill two roles: &lt;strong&gt;1)&lt;/strong&gt; To check the existence of the [in] and [out] directories in the current directory where the program was started from and &lt;strong&gt;2)&lt;/strong&gt; To monitor the [in] directory .&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//dirmgr.cpp&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="s"&gt;"dirmgr.hpp"&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;filesystem&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;iostream&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;_NS_fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;filesystem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Public Methods
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;check_dirs&lt;/strong&gt;()&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; Fulfills the role mentioned in 1). It was defined as static method, that is, it does not need to be invoked through an object, this can be done via class directly, such as at &lt;em&gt;main.cpp&lt;/em&gt;:6.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;check_dirs&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;13&lt;/span&gt;    &lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="mi"&gt;14&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;15&lt;/span&gt;       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"in"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="mi"&gt;16&lt;/span&gt;          &lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;create_directory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"in"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="mi"&gt;17&lt;/span&gt;       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"out"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="mi"&gt;18&lt;/span&gt;          &lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;create_directory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"out"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;19&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;20&lt;/span&gt;    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;exception&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;21&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;22&lt;/span&gt;       &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Error on trying to create [in]/[out] directories."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;23&lt;/span&gt;       &lt;span class="n"&gt;cerr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;what&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;24&lt;/span&gt;       &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;25&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;26&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;br&gt;
&lt;em&gt;&lt;strong&gt;start_watching&lt;/strong&gt;(string &lt;strong&gt;path&lt;/strong&gt;)&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; Creates an object of class &lt;strong&gt;&lt;a href="https://en.cppreference.com/w/cpp/header/thread" rel="noopener noreferrer"&gt;thread&lt;/a&gt;&lt;/strong&gt; on the &lt;a href="https://stackoverflow.com/questions/2308751/what-is-a-memory-heap" rel="noopener noreferrer"&gt;heap&lt;/a&gt; and stores its address in the pointer &lt;strong&gt;obj_th&lt;/strong&gt;. The class constructor used in this case takes 3 arguments as input: &lt;strong&gt;1&lt;/strong&gt;. the address of the method that will be executed in a new thread (DirManager :: &lt;strong&gt;watching_task&lt;/strong&gt; in this case), &lt;strong&gt;2&lt;/strong&gt;. the pointer to the instance of the class that has the method (&lt;em&gt;&lt;a href="https://en.cppreference.com/w/cpp/language/this" rel="noopener noreferrer"&gt;this pointer&lt;/a&gt;&lt;/em&gt; in this case), and &lt;strong&gt;3&lt;/strong&gt;. the argument used by the method (&lt;strong&gt;path&lt;/strong&gt;).

&lt;p&gt;The private member &lt;strong&gt;obj_linked_thd&lt;/strong&gt; receives the contents of &lt;strong&gt;obj_th&lt;/strong&gt; in order to be accessed in the class destructor (dirmgr.cpp:8).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;start_watching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;41&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;42&lt;/span&gt;    &lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="mi"&gt;43&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;44&lt;/span&gt;       &lt;span class="kr"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;obj_th&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kr"&gt;thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;watching_task&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;45&lt;/span&gt;       &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;obj_linked_thd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;obj_th&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;46&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;47&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;48&lt;/span&gt;    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;exception&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;49&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;50&lt;/span&gt;       &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cerr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;what&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="sc"&gt;'\n'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;51&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;52&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;53&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;br&gt;
&lt;em&gt;&lt;strong&gt;stop_watching&lt;/strong&gt;()&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; Just sets the data member &lt;strong&gt;stop_flag&lt;/strong&gt; to true.

&lt;p&gt;&lt;em&gt;&lt;strong&gt;~DirManager&lt;/strong&gt;()&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; The class destructor uses the &lt;strong&gt;&lt;a href="https://en.cppreference.com/w/cpp/thread/thread/join" rel="noopener noreferrer"&gt;join&lt;/a&gt;()&lt;/strong&gt; method of the &lt;strong&gt;thread&lt;/strong&gt; class. This causes the parent thread to wait for the child thread to finish before proceeding. Since the &lt;strong&gt;obj_dm&lt;/strong&gt; (main.cpp:7) object will be dropped at the end of program execution, this ensures that the child thread has completed before exiting the program, avoiding problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On line 9, the &lt;em&gt;delete&lt;/em&gt; operator is used to release the allocated memory addressed by &lt;strong&gt;obj_linked_thd&lt;/strong&gt; as it was allocated through the &lt;em&gt;new&lt;/em&gt; operator (line 44). Since C++11, the standard library has been supported &lt;a href="https://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one" rel="noopener noreferrer"&gt;smart pointers&lt;/a&gt;, making it unnecessary to use the delete operator to release allocated memory.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::~&lt;/span&gt;&lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;obj_linked_thd&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;    &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;obj_linked_thd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h4&gt;
  
  
  Private Methods
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;watching_task&lt;/strong&gt;(string &lt;strong&gt;path&lt;/strong&gt;)&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; Initially, it uses the &lt;strong&gt;count_items()&lt;/strong&gt; method to get the number of files in &lt;strong&gt;path&lt;/strong&gt; before entering the loop in which monitoring will be active while &lt;strong&gt;stop_flag&lt;/strong&gt; is false. The thread is suspended inside the loop for 3 seconds (simulating a timer with this interval). Then the number of files is cheked; if it is larger than previous one, it means that a new file has been created.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;27&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;watching_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;28&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;29&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;files_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;count_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="mi"&gt;30&lt;/span&gt;    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;stop_flag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;31&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;32&lt;/span&gt;       &lt;span class="n"&gt;this_thread&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;sleep_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chrono&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="mi"&gt;33&lt;/span&gt;       &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Monitoring [in] directory, interval 3 secs."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;34&lt;/span&gt;       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;count_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;files_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;35&lt;/span&gt;          &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"New file created."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;36&lt;/span&gt;       &lt;span class="n"&gt;files_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;count_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;37&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="mi"&gt;38&lt;/span&gt;    &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Monitor finished."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;39&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;br&gt;
&lt;em&gt;&lt;strong&gt;count_items&lt;/strong&gt;(string &lt;strong&gt;path&lt;/strong&gt;)&lt;/em&gt;&lt;strong&gt;:&lt;/strong&gt; Traverses all elements of the directory contained in &lt;strong&gt;path&lt;/strong&gt; through the &lt;strong&gt;&lt;em&gt;&lt;a href="https://en.cppreference.com/w/cpp/filesystem/directory_iterator" rel="noopener noreferrer"&gt;directory_iterator&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;. Each element &lt;strong&gt;&lt;em&gt;p&lt;/em&gt;&lt;/strong&gt; is an object of the &lt;strong&gt;&lt;a href="https://en.cppreference.com/w/cpp/filesystem/directory_entry" rel="noopener noreferrer"&gt;directory_entry&lt;/a&gt;&lt;/strong&gt; class. If &lt;strong&gt;p&lt;/strong&gt; is a file (line 63), the counter is incremented.&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;58&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;count_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;59&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;60&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;61&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;directory_iterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="mi"&gt;62&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;63&lt;/span&gt;       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_NS_fs&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;is_regular_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
&lt;span class="mi"&gt;64&lt;/span&gt;          &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;65&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;66&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;67&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;br&gt;
The program entry point:&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//main.cpp&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="s"&gt;"dirmgr.hpp"&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;iostream&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;    &lt;span class="n"&gt;DirManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;check_dirs&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;    &lt;span class="n"&gt;DirManager&lt;/span&gt; &lt;span class="n"&gt;obj_dm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;8&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;obj_dm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start_watching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"./in"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;       &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Could not start Directory Monitor."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;11&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;12&lt;/span&gt;   &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="mi"&gt;13&lt;/span&gt;   &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;14&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;15&lt;/span&gt;       &lt;span class="n"&gt;this_thread&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;sleep_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chrono&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="mi"&gt;16&lt;/span&gt;       &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Main thread alive."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;17&lt;/span&gt;   &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="mi"&gt;18&lt;/span&gt;   &lt;span class="n"&gt;obj_dm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stop_watching&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="mi"&gt;19&lt;/span&gt;   &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Main thread finished."&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;20&lt;/span&gt;   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;EXIT_SUCCESS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  Execution:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev-to-uploads.s3.amazonaws.com/i/2vrhfbdusr179s9kstux.png" rel="noopener noreferrer"&gt;https://dev-to-uploads.s3.amazonaws.com/i/2vrhfbdusr179s9kstux.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a terminal the program is launched. During its execution, in another terminal a file is created in the [in] directory. Then the message “New file created.” is shown in the fisrt one.&lt;/p&gt;

&lt;p&gt;It is important to note that in this multithreading use model, the execution is asynchronous, that is, one task does not need to wait for another to finish. Therefore, the ending message of the main thread is shown before the ending message of the child thread, although &lt;strong&gt;obj_dm.stop_watching()&lt;/strong&gt; is invoked before the line where the ending message of the main thread is printed out (lines 18–19).&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
Full repo and build info:&lt;br&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/prog-lessons" rel="noopener noreferrer"&gt;
        prog-lessons
      &lt;/a&gt; / &lt;a href="https://github.com/prog-lessons/multithreading_fs_sample" rel="noopener noreferrer"&gt;
        multithreading_fs_sample
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Small sample program to demonstrate multithreading and filesystem lib usage in CPP17.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;C++&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/prog-lessons/multithreading_fs_sample/tree/master/threads-fs" rel="noopener noreferrer"&gt;Threads &amp;amp; FileSystem (C++17)&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/prog-lessons/multithreading_fs_sample" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;

</description>
      <category>cpp</category>
      <category>multithreading</category>
      <category>coding</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
