Skip to content

Latest commit

 

History

History
79 lines (49 loc) · 2.23 KB

Step_1.md

File metadata and controls

79 lines (49 loc) · 2.23 KB

Step 1: Reimplement LockGuard

To duplicate

In /src/Step_1/ directory run make. Executable will build as Lock.out. To run executable, run ./Lock.out.

Files

Results

The test code passed. It performed the same when std::lock_guard was referenced, and when chal::LockGuard was referenced. It produced this output, which matched expectations:

armaan@ubuntuVM:Step_1$ ./Lock.out 
thread #7
thread #8
thread #9
thread #6
thread #10
thread #5
thread #4
thread #3
thread #2
thread #1

Test conditions

  • Pass: The test code performs the same with my namespace and class, chal::LockGuard, as it would with std::lock_guard.
  • Fail: Any other result.

Method

Research

Details about my research into lock_guard, mutex, and testing are available here: Reference in Appendix

Coding

As this is a first step in a larger project, I intended to replicate already-working code. To that end, I copied std::lock_guard into a new header file, fixed references to an STD object that was out of namespace, and encapsulated it with my own namespace. To test, I took generic multithread example code that uses std::lock_guard and modified it to use my namespace and class. See Reference in Appendix for details.

Requirements

  1. Reimplement c++11 lock_guard (NOT use std::lock_guard). Use namespace to allow you to call your class impl "lock_guard" and not conflict with std::lock_guard

    LockGuard.h // header file only impl

Prelims

Parsing Requirements

Initially had trouble parsing requirements. See Reference in Appendix for details.

Environment

Performed all coding in a virtual machine running Ubuntu 17.10, 64-bit. To test build environment, created hello world function, and built with makefile. Build successful.

Refamiliarization with C++

Needed to refamiliarize myself with C++ after spending large amount of time with C and Python. See Reference in Appendix for details.