A real-time collaborative text editing system that uses Conflict-Free Replicated Data Types (CRDT) for lock-free synchronization between multiple users.
SyncText allows multiple users (3-5) to edit the same document simultaneously with automatic conflict resolution using the Last-Writer-Wins (LWW) strategy. The system operates entirely lock-free, relying on CRDT properties for consistency.
- User registration in shared memory registry
- Automatic file change detection using file monitoring
- Real-time terminal display of document state
- Change tracking with line and column precision
- Support for up to 5 concurrent users
- POSIX message queues for inter-process communication
- Multi-threaded architecture (main thread + listener thread)
- Automatic broadcasting after every 5 operations
- Real-time update delivery to all active users
- Conflict detection based on line and column overlap
- Last-Writer-Wins (LWW) conflict resolution
- Timestamp-based operation ordering
- Automatic document synchronization
- Convergence guarantee across all users
- Linux (Ubuntu 20.04 or later recommended)
- GCC compiler (version 9.4.0 or later)
- pthread library (POSIX threads)
- rt library (POSIX real-time extensions)
- Standard C libraries
makeThis will compile all source files and create the editor executable.
make cleanmake cleanallOpen separate terminals for each user and run:
Terminal 1:
./editor user_1Terminal 2:
./editor user_2Terminal 3:
./editor user_3You can also use the Makefile shortcuts:
make run1 # Terminal 1
make run2 # Terminal 2
make run3 # Terminal 3- Start the editor program with a unique user_id
- The program creates a local document file:
<user_id>_doc.txt - Open this file in any text editor (vim, nano, gedit, VS Code, etc.)
- Make changes and save the file
- The program automatically detects changes and displays them
- Changes are broadcast to other users after every 5 operations
- Conflicts are automatically resolved using CRDT principles
# Terminal 1
$ ./editor user_1
Starting SyncText Editor for user_1
========================================
Registered as user_1
Message queue: /queue_user_1
Message queue created: /queue_user_1
Creating initial document: user_1_doc.txt
Active users: user_1
You can now edit user_1_doc.txt in any text editor.
Changes will be detected and synchronized automatically.
Press Ctrl+C to exit.
========================================
Document: user_1_doc.txt
Last updated: 14:05:30
----------------------------------------
Line 0: Hello World
Line 1: This is a collaborative editor
Line 2: Welcome to SyncText
Line 3: Edit this document and see real-time updates
----------------------------------------
Active users: user_1
Monitoring for changes...
========================================.
├── common.h # Common header with data structures and declarations
├── editor.c # Main program with monitoring loop and threading
├── user_management.c # User registration and shared memory management
├── file_monitor.c # File monitoring and change detection
├── message_queue.c # Message queue operations and broadcasting
├── crdt_merge.c # CRDT merge algorithm and conflict resolution
├── utils.c # Utility functions
├── Makefile # Build configuration
├── README.md # This file
└── DESIGNDOC.md # Design documentation
- Start 2-3 users in separate terminals
- Each user edits different lines in their document
- Save the files
- Verify all users see all changes after synchronization
- Start 2 users
- Both users edit the same line at approximately the same time
- Save both files
- Verify that the update with the later timestamp wins
- Check that both users converge to the same final state
- Start user_1 and user_2
- Make some edits
- Start user_3
- Verify user_3 can see existing users
- Make edits from all users and verify synchronization
- Start multiple users
- Make 5+ changes rapidly in one user's document
- Verify broadcasting happens after 5 operations
- Check that all users receive and merge the updates
- Run
make cleanallto remove stale shared memory segments - Ensure you have permissions to create shared memory
- Run
make cleanallto remove stale message queues - Check
/dev/mqueue/for existing queues
- Ensure you're saving the file after editing
- Check that the file modification time is changing
- Verify the monitoring interval (default: 2 seconds)
- Ensure all users are running on the same machine
- Check that shared memory is properly initialized
- Verify user registration with active user list
Press Ctrl+C in any terminal to gracefully shut down that user. The program will:
- Unregister the user from shared memory
- Close and remove the message queue
- Clean up resources
- The system is completely lock-free, using atomic operations and CRDT properties
- All users must run on the same machine (shared memory limitation)
- Maximum 5 concurrent users supported
- Document files are automatically created with initial content
- Synchronization happens after every 5 operations or periodically
- Timestamps are in milliseconds for precise conflict resolution
Computing Lab (CS69201) Project SyncText - CRDT-Based Collaborative Text Editor