{"type": "session", "harness": "deepseek-harness", "id": "sys-0023", "name": "RTOS concepts"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} {"type": "message", "message": {"role": "user", "content": "What are RTOS concepts and when do I need one?"}} {"type": "message", "message": {"role": "assistant", "content": "```\nRTOS (Real-Time Operating System):\n- Deterministic task scheduling\n- Priority-based preemptive multitasking\n- Bounded interrupt latency\n- Memory management (no virtual memory)\n\nFreeRTOS tasks:\n```c\nvoid vTaskFunction(void *pvParameters) {\n for (;;) {\n // Do work\n vTaskDelay(pdMS_TO_TICKS(100));\n }\n}\n\nxTaskCreate(vTaskFunction, \"Task1\", 256, NULL, 1, NULL);\nvTaskStartScheduler();\n```\n\nSynchronization:\n- Semaphore: binary or counting\n- Mutex: mutual exclusion (priority inheritance)\n- Queue: inter-task communication\n- Event Group: multiple event flags\n\nWhen to use RTOS:\n- Hard real-time constraints (motor control, safety)\n- Multiple independent tasks\n- Low-latency interrupt handling\n- Resource-constrained devices\n\nWhen NOT to use:\n- Simple polling loops work fine\n- No timing requirements\n- Single-threaded application\n- Linux/Android sufficient\n\nAlternatives:\n- Bare metal (no OS)\n- Arduino (simplified RTOS)\n- Zephyr (modern, scalable)\n- RIOT (energy-efficient IoT)\n```"}}