Editing User:Pulkit Mittal/GSOC2014/Midterm

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 10: Line 10:
 
I am done with making ''cllazyfile'' thread safe. I also have covered around 6K lines of codes of ''clstepcore'' library.
 
I am done with making ''cllazyfile'' thread safe. I also have covered around 6K lines of codes of ''clstepcore'' library.
  
Considering the fact ''cllazyfile'', ''cleditor'' & ''cldai'' all contain on avg ~3K lines of code and ''clstepcore'' contains ~17K lines of code. It can be safely said that I am 35% done with the thread safe objective.  
+
Considering the fact ''cllazyfile'', ''cleditor'' & ''cldai'' all contain on avg ~3K lines of code and ''clstepcore'' contains ~17K line of codes. It can be safely said that I am 35% done with the thread safe objective.  
Its clear that I am lagging behind (ideally it should have been around 50%), but my progress is not disappointing either.
+
Its clear that I am lagging behind (ideally it should have around 50%), but my progress is not disappointing either.
  
  
Line 22: Line 22:
 
# An instance of the class is created. The feature/s (same or different) to be checked are called twice in serial manner.
 
# An instance of the class is created. The feature/s (same or different) to be checked are called twice in serial manner.
 
# Another instance of the class is created. This time the feature/s (same or different) to be checked are called in parallel by different threads, with the same load as in step 1. The load is kept-heavy so that the operations by the two threads overlap in time domain.
 
# Another instance of the class is created. This time the feature/s (same or different) to be checked are called in parallel by different threads, with the same load as in step 1. The load is kept-heavy so that the operations by the two threads overlap in time domain.
# Both instances are compared for any disparity. Harmless differences like order of occurrence, of various entities inside the data structures, are ignored. For checking the internal data structures, already available public API's are used. However wherever needed new API's have also been created for this purpose.
+
# Both instances are compared for any disparity. Harmless differences like order of occurrence, of various entities inside the data structures, of the class are ignored. For checking the internal data structures, already available public API's are used. However wherever needed new API's have also created for this purpose.
  
 
The step 2 & 3 are repeated multiple times. If a disparity is found it is immediately reported and the check fails.  
 
The step 2 & 3 are repeated multiple times. If a disparity is found it is immediately reported and the check fails.  
  
 
=== Development Methodology ===
 
=== Development Methodology ===
The features which were targeted were the public APIs. ''e.g.'' For cllazyfile library the functions of the class ''lazyInstMgr'' were targeted as it was the only class which was meant to be visible to the user of that library. The code changes can be roughly divided into 2 parts.
+
The features which were targeted were the public APIs. ''e.g.'' For cllazyfile library the functions of the class ''lazyInstMgr'' were targeted as it was the only class which was meant to be visible to the user of that library.
===== Pre-Processing =====  
+
 
This part mainly consist of code refactoring. These changes by themselves do not make the code thread safe, however they make the job of making code thread safe much easier. No mutex (or equivalent) is invoked in this part. Couple of examples where I needed preprocessing are:
+
The code changes can be roughly divided into 2 parts.
* ''gennodelist'' and ''gennode'' classes: This link-list structure was difficult to make thread-safe in its original form. This was because an operation on one node could change the state of another node. The classes were modified so that a node could modify state of another node only through its parent list.
+
==== Pre-Processing ====
* ExpDict.h/.cc/.inline.cc files: These contain multiple classes which were similar and not thread-safe. Hence another class was created which would contain all the features and act as superclass. Now only this new superclass was needed to be made thread safe. Lot of duplicated code was removed this way.
+
This part mainly consist of code refactoring. These changes do not make the code thread safe, however they make the job of making code thread safe easier. No mutex (or equivalent) is invoked in this part. Couple of examples where I needed preprocessing were:
===== Thread-Safety =====
+
* ''SingleLinkList'' and ''SingleLinkNode'' classes: This link-list structure was difficult to make thread-safe in its original form. This was because an operation on one node could change the state of another node. The classes were modified so that a node could modify state of another node only through its parent list.
 +
* ExpDict.h/.cc/.inline.cc files: These contain multiple classes which were similar and not thread-safe. Hence another class was created which would contain all the features and act as superclass. Now only this new superclass was needed to be made thread safe.
 +
==== Thread-Safety ====
 
A feature could be thread-unsafe due to the following reasons.
 
A feature could be thread-unsafe due to the following reasons.
 
# It does file I/O.
 
# It does file I/O.
 
# It modifies the state of a thread-unsafe data structure / counter.
 
# It modifies the state of a thread-unsafe data structure / counter.
 
# It modifies the state of multiple data structures / counters which should be consistent at all time.
 
# It modifies the state of multiple data structures / counters which should be consistent at all time.
# It provides a reference to a read unsafe data structure to the user.
+
# It reads from read unsafe data structure.
For 1. & 3. the only way out was using fat lock. For 2. I had an option of using a fat-lock or making the structure itself thread safe. I chose the latter in cases where many classes were taking dependency on the same data-structure. Structures described in 4. were found in ''cllazyfile'' library. Whenever such a feature was invoked, clones of that data structure were made.
+
For 1. & 3. the only way out was using fat lock. For 2. I had an option of using a fat-lock or making the structure itself thread safe. I chose the latter if many classes were using the same data-structure. Structures described in 4. were found in ''cllazyfile'' library. In such cases whenever such a feature was invoked, clones of that data structure were made.
  
 
For locking either a ''std::mutex'' or a ''std::recursive_mutex'' was used. The changes also included invoking the HAVE_STD_THREADS macro in the cmake files.
 
For locking either a ''std::mutex'' or a ''std::recursive_mutex'' was used. The changes also included invoking the HAVE_STD_THREADS macro in the cmake files.
  
 
=== The Grey Area ===
 
=== The Grey Area ===
I started this project with literally no knowledge of ''cmake'' files. But in-order to compile my changes I had to modify some of the existing cmake files. Unlike my C++ coding, I am not very confident about these modifications. They should be looked into carefully in future before merging the branches.
+
I started this project with literally no knowledge of ''cmake'' files. But in-order to compile my changes I had to modify some of the cmake files. Unlike my C++ coding, I am not very confident about these modifications. They should be looked into carefully in future before merging the branches.
  
  

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)