Skip to content

PramithaMJ/thread-lifecycle-visualizer

Repository files navigation

Thread Lifecycle Visualizer

An interactive web-based visualization tool for understanding thread lifecycle states and transitions. This educational tool helps students visualize and interact with the different states a thread can be in during its lifecycle.

Features

  • Interactive visualization of thread lifecycle states
  • Real-time state transitions with animations
  • Multiple thread creation and management
  • Detailed explanation of each thread state
  • Transition log to track state changes
  • User-friendly controls to manipulate thread states
  • Thread scheduling simulation with multiple algorithms
  • Enhanced concurrency issue demonstrations with step-by-step visualizations:
    • Race conditions with memory access visualization and timeline
    • Deadlocks with circular dependency visualization and resource tracking
    • Livelocks with cyclic behavior visualization and attempted resource acquisitions
  • Shared memory visualization and access patterns
  • Interactive tutorials with step-by-step guidance
  • Comprehensive help center with educational content
  • Detailed explanations of concurrency issues with code examples and solutions

Thread States Visualized

  1. New - Thread is created but not yet started
  2. Runnable - Thread is ready to run when given CPU time
  3. Running - Thread is currently executing
  4. Blocked - Thread is waiting for a monitor lock
  5. Waiting - Thread is waiting indefinitely for another thread
  6. Timed Waiting - Thread is waiting for a specified time
  7. Terminated - Thread has completed execution

Controls

  • Create New Thread - Creates a thread in the "New" state
  • Start Thread - Transitions a thread from "New" to "Runnable"
  • Resume - Transitions a thread from "Runnable" to "Running"
  • Pause - Transitions a thread from "Running" to "Runnable"
  • Sleep - Transitions a thread from "Running" to "Timed Waiting"
  • Wake Up - Transitions a thread from "Waiting/Timed Waiting" to "Runnable"
  • Block - Transitions a thread from "Running" to "Blocked"
  • Unblock - Transitions a thread from "Blocked" to "Runnable"
  • Terminate - Transitions any thread to "Terminated"

How to Use

Quick Start Options

Option 1: Direct browser open

  1. Navigate to the project folder
  2. Open the open_visualizer.html file with your browser

Option 2: Using launcher scripts

  • On Mac/Linux:

    • Open Terminal in the project folder
    • Run chmod +x run_visualizer.sh (first time only)
    • Run ./run_visualizer.sh
  • On Windows:

    • Double-click run_visualizer.bat

Option 3: Cross-browser testing

To test the visualizer across multiple browsers:

# Make the script executable first
chmod +x browser_test.sh

# Run the test script
./browser_test.sh

This will attempt to open the visualizer in Chrome, Firefox, Safari (macOS only), and Edge (if available) for cross-browser testing. Use the included test_plan.md to document your testing results.

Using the Visualizer

  1. Click "Create New Thread" to create a new thread
  2. Click on any thread to select it
  3. Use the control buttons to transition the selected thread between states
  4. Watch the transition log to track state changes
  5. Click the tutorial button (graduation cap icon) to start interactive tutorials
  6. Click the help button (question mark icon) to open the educational help center
  7. Try the concurrency demonstrations to understand common concurrency problems

Keyboard Shortcuts

  • N - Create New Thread
  • S - Start Thread
  • P - Pause
  • R - Resume
  • Z - Sleep
  • W - Wake Up
  • B - Block
  • U - Unblock
  • T - Terminate
  • H - Toggle Help Center
  • G - Toggle Tutorial Guide

Educational Tools

Tutorial Guide

The visualizer includes a comprehensive tutorial guide with step-by-step instructions for:

  • Thread basics and states
  • Working with multiple threads
  • Understanding thread scheduling
  • Exploring concurrency issues
  • Using shared memory

Help Center

An in-depth help center provides detailed explanations on:

  • Thread lifecycle states
  • State transitions
  • Common threading problems
  • Best practices for thread management

Enhanced Concurrency Demonstrations

Interactive demonstrations of common concurrency issues with detailed visualizations:

Race Condition Visualization

  • Step-by-step execution tracking with detailed explanations for each step
  • Visual timeline showing thread events with timestamps
  • Memory access visualization showing reads and writes
  • Resource value tracking and updates
  • Clear explanation of the race condition outcome
  • Solution box with synchronized code example

Deadlock Visualization

  • Step-by-step progress tracking with detailed explanations
  • Visual timeline showing resource acquisition and waiting
  • Clear resource ownership indicators
  • Wait visualization showing blocked threads
  • Deadlock detection with visual dependency diagram
  • Solution with consistent lock ordering example

Livelock Visualization

  • Step-by-step progression with detailed explanations
  • Timeline showing repeated resource acquisition attempts
  • Resource release visualization during conflict avoidance
  • Visual representation of continuous cycle without progress
  • Comparison with deadlock behavior
  • Solution with randomized backoff strategy

Each demonstration includes:

  • Detailed explanations for every step of the visualization
  • Color-coded timeline events for different threads
  • Interactive visual indicators for resource access
  • Code examples for both problematic and fixed implementations

Mobile Support

The Thread Lifecycle Visualizer is fully responsive and works well on mobile devices:

  • Optimized layouts for tablets and phones
  • Special optimizations for very small screens (under 375px)
  • Touch-friendly controls and buttons
  • Simplified views for better mobile experience
  • Accessible educational content on all devices

Deployment

This project can be easily deployed to GitHub Pages:

  1. Fork this repository
  2. Go to the repository settings
  3. Navigate to "Pages" in the sidebar
  4. Select the main branch as the source
  5. Click "Save"

Your visualization will be live at https://[your-username].github.io/thread-lifecycle-visualizer/

Testing

To test the integration of all components:

npm test

or run directly:

./test_integration.sh

This will verify that all necessary files are present and properly linked, then start a local server for manual testing.

Technical Details

This project is built using:

  • HTML5
  • CSS3
  • Vanilla JavaScript (ES6+)

No external libraries or frameworks are used, making it lightweight and easy to understand.

License

MIT License - Feel free to use, modify, and distribute this project for educational purposes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Releases

No releases published

Packages

 
 
 

Contributors