dhananjai m. rao ([email protected])[email protected] cse department, oxford, ohio using c++11 to...
TRANSCRIPT
![Page 1: Dhananjai M. Rao (raodm@miamioh.edu)raodm@miamioh.edu CSE Department, Oxford, OHIO Using C++11 to teach Concurrency and Parallelism Concepts](https://reader036.vdocuments.us/reader036/viewer/2022082816/56649d005503460f949d2f3c/html5/thumbnails/1.jpg)
Dhananjai M. Rao ([email protected])
CSE Department, Oxford, OHIO
Using C++11 to teach Concurrency and Parallelism
Concepts
![Page 2: Dhananjai M. Rao (raodm@miamioh.edu)raodm@miamioh.edu CSE Department, Oxford, OHIO Using C++11 to teach Concurrency and Parallelism Concepts](https://reader036.vdocuments.us/reader036/viewer/2022082816/56649d005503460f949d2f3c/html5/thumbnails/2.jpg)
• Students consistently report steep, multifaceted learning curve and challenges due to: – Introduction of new programming language
• Prerequisite courses are predominantly taught in Java• Students struggle with C-language
– Initiation to Linux• Course introduces Linux and predominantly uses a Command
Line Interface (CLI) based laboratory environment – A Significant change from a Graphical User Interface (GUI) driven
Windows™ platform
– Introduction and extensive use of PDC concepts• A paradigmatic change from the traditional serial programming
that the students are conversant with.
Motivation
![Page 3: Dhananjai M. Rao (raodm@miamioh.edu)raodm@miamioh.edu CSE Department, Oxford, OHIO Using C++11 to teach Concurrency and Parallelism Concepts](https://reader036.vdocuments.us/reader036/viewer/2022082816/56649d005503460f949d2f3c/html5/thumbnails/3.jpg)
• In Fall 2012, C++11 was used instead of C to ameliorate the steep learning curves faced by students– Continue to build upon student’s object-oriented skills– Use STL data structures to ease programming– Encouraged use of standard algorithms
• Supports automatic multi-threading via compiler flags• Permit the use of C++ lambdas (makes programming convenient and
concise)
– Enables seamless use of system calls exposed only in C language– C++11 provides many modern design patterns for managing
concurrency and parallelism• Threading constructs are very streamlined and straightforward
– Simplified, stream-based I/O• For console I/O, files, sockets, and IPC-pipes
Proposed using C++ rather than C
![Page 4: Dhananjai M. Rao (raodm@miamioh.edu)raodm@miamioh.edu CSE Department, Oxford, OHIO Using C++11 to teach Concurrency and Parallelism Concepts](https://reader036.vdocuments.us/reader036/viewer/2022082816/56649d005503460f949d2f3c/html5/thumbnails/4.jpg)
Sample C++ Code Fragments
int num = 0;// A mutex to synchronize // access to numstd::mutex gate;
void threadMain() { // Automatic lock & unlock std::lock_guard<std::mutex> guard(gate); for(int i=0; (i<1000); i++) { num++; }}
void producer(int num) { for(int i = 0; (i < num); i++){ std::unique_lock<std::mutex>
lock(queueMutex); data_cond.wait(lock, []{return queue.size() < MaxQSize; }); queue.push(rand() % 10000); data_cond.notify_one(); }}
using namespace std;int main() { promise<int> prom; async(launch::async, thread1, 99999, std::ref(prom)); future<int> result = std::async(launch::async, thread2, 50000, std::ref(prom)); // Do some foreground work here! cout << "Result = ” << result.get() << std::endl; return 0;}
![Page 5: Dhananjai M. Rao (raodm@miamioh.edu)raodm@miamioh.edu CSE Department, Oxford, OHIO Using C++11 to teach Concurrency and Parallelism Concepts](https://reader036.vdocuments.us/reader036/viewer/2022082816/56649d005503460f949d2f3c/html5/thumbnails/5.jpg)
• Pedagogical experiences indicate C++11 was effective in teaching concurrency and parallelism– It alleviated the steep learning curve experienced by students
• Permitted coverage of pointers and explicit dynamic memory management later in the course when students were already comfortable with C++.
– Helped to focus on core concepts rather than routine problem solving aspects– Effective for covering modern design patterns related to parallelism and
concurrency• Many of the terms and concepts are portable to other popular programming languages
– Eases use of OS system calls and other C-language API• Student experience and feedback was very positive
– Course evaluations were very positive: 3.38 (SD: 0.84) out of 4.0– Department plans to use C++11 in Fall 2013– If experiences and student feedback remain positive, then C++11 will be
permanently adopted
Conclusions