Implement mutex locking for WindowsBRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: Sean, Daniel RossbergTags: C, C++, Windows, mutex, SMP, threading

BRL-CAD implements support for running in parallel on computers with multiple CPUs or cores. However, there are lots of ways to run in parallel. BRL-CAD runs on Windows, but presently only in a single-threaded mode. To make it work in parallel, we need to define how threads acquire a mutex lock.

This task involves implementing the necessary logic to acquire and release a mutex or semaphore on Windows. You can use either, but probably want to call CreateMutex(). This requires a very minor source code modification to just one file, but make sure it works with a simple test program. Make your test program call bu_semaphore_init()+bu_semaphore_acquire()+bu_semahpore_release(), see include/bu.h for API docs.

References:

Code:

  • src/libbu/semaphore.c

 

Uploaded Work
File name/URLFile sizeDate submitted
semaphore.c12.8 KBDecember 09 2012 01:50 UTC
semaphore.patch1.5 KBDecember 09 2012 02:01 UTC
semaphore.patch1.7 KBDecember 09 2012 22:20 UTC
semaphore.patch1.8 KBDecember 11 2012 02:36 UTC
semaphore.patch2.1 KBDecember 11 2012 02:41 UTC
semaphore.patch1.7 KBDecember 12 2012 00:05 UTC
Comments
Melange on December 7 2012 03:01 UTCTask Claimed

I would like to work on this task.

Sean on December 7 2012 03:09 UTCTask Assigned

This task has been assigned to Arjun Govindjee. You have 48 hours to complete this task, good luck!

Melange on December 9 2012 01:50 UTCReady for review

The work on this task is ready to be reviewed.

Melange on December 9 2012 02:03 UTCPatch

I submitted a patch as suggested on your website. I created it with SVN diff, is this OK, or should I use the bsd diff utility?

Melange on December 9 2012 03:09 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on December 9 2012 05:09 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 9 2012 05:09 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Sean on December 9 2012 05:14 UTClooking good

Nice work, only a couple minor issues I see...


Instead of including windows.h directly, you should include our "bio.h" header (before bu.h,  after math.h).


Your indentation is wrong.  We use a mix of tabs and spaces.  See our HACKING file for style guidelines or you can look at our existing code to try and match it exactly.  Basically the indentation levels are 4spaces, 1tab, 1tab+4spaces, 2tabs, 2tabs+4spaces, etc., not just tabs and not just spaces.


Lastly, did you attempt to compile the code?  Did you try to run it?


 

Melange on December 9 2012 06:58 UTCTesting Questions

Ok i can fix the indentation pretty easily, when I first read the vi tabstop instructions I was a little confused because well it seemed like it was mixing tabs and spaces (which to me is quite unusual). I can fix the header include too.


 


I can compile the code with no errors, but I have one question, how can I test it? I wrote a test program, but I cannot compile it, myself being unfamiliar with visual c++ express 2010, because I don't know how to set up a project with the correct access to include files and libraries, etc. Any advice on that would be helpful.

Melange on December 9 2012 22:20 UTCReady for review

The work on this task is ready to be reviewed.

Melange on December 9 2012 22:23 UTCQuestions solved

Ok, I managed to test the code, and it does indeed work (I had to use CMake to create the Visual Studio project - something I had not anticipated). I fixed the indents and included bio.h too.


Now I'm actually finished :)

Melange on December 10 2012 05:45 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Daniel Rossberg on December 10 2012 10:12 UTCI can't apply your patch

because it refers to files I don't have ;)



  • Desktop/semaphore.old.c

  • Desktop/semaphore.c


Please modify the file inside your subversion checkout (i.e. src/libbu/semaphore.c).  Subversion will take care of your lokal changes and should generate a nice patchfile of these changes vs. the version on the surceforge server.

Daniel Rossberg on December 10 2012 10:12 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Daniel Rossberg on December 10 2012 10:12 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Melange on December 11 2012 02:41 UTC(clearly a pro at svn)

I hope I got it right this time (the very last file I submitted - look at the time)...I've never used svn before (I use git and at that I never make patch files). What I did this time was I checked out the latest revision and used "Create patch..."


Before I had been using the TortoiseSVN diff viewer program and clicking "create unified diff file", which evidently creates something very different than create patch.


-Arjun

Melange on December 11 2012 02:41 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 11 2012 08:49 UTCTwo things


  • don't include windows.h, it's already included in bio.h (which is ok)

  • you made a wrong correction to acquire (aquire)


BTW, you can open your patch-file in a text editor.  This is what I do to have a first look at your results.

Daniel Rossberg on December 11 2012 08:50 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Daniel Rossberg on December 11 2012 08:50 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Melange on December 12 2012 00:05 UTCReady for review

The work on this task is ready to be reviewed.

Melange on December 12 2012 00:11 UTCSorry

Wow...svn is really messing me up...


Basically here is the whole story:


I downloaded the "source" package from sourceforge instead of using svn originally.


That package did not yet have the typo fix for aquire, so when I used the version from svn to make the patch, it created that false fix.


I had thought that I had removed it and fix the whole issue before uploading, but I guess I messed up.


About the windows.h...I have no idea how that is still there...I removed that when I included bio.h.


Again, I apologize for my extreme incompetence with svn and patch files, especially on windows :(


I think I'll be using linux from now on (if I do more BRLCAD projects) so it will be easy to manage everything with svn and not screw up again. (Windows + Coding + No Experience Coding on Windows = Disaster...)


-Arjun

Melange on December 12 2012 14:51 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Daniel Rossberg on December 12 2012 15:50 UTCThis could work

The patch has to be tested more extensively than I did but this would be a different task.  So far: Well done!

Daniel Rossberg on December 12 2012 15:51 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 17 2012 23:55 UTCfollow-on task

A follow-on task has been posted:


http://www.google-melange.com/gci/task/view/google/gci2012/8095204


 

Sean on January 14 2013 15:17 UTCthank you

As GCI comes to a close, we wanted to take the time to say THANK YOU for all your efforts.  This comment interface closes after GCI is over, so you're encouraged to join our mailing list where we'll be announcing contributions from GCI participants like yourelf over the upcoming months: 


https://lists.sourceforge.net/lists/listinfo/brlcad-news


If you've provided your full name, we'll be sure to credit you in our authorship documentation and you'll see your name in a future announcement.  If you contact us at devs@brlcad.org or via IRC, we'll even let you know when your work is integrated and follow up with updates.  You're welcome and encouraged to contact us any time, especially if you have a question about how to continue participating in Open Source after GCI is over, but even if just to keep in touch.  Note that ongoing participation in Open Source is one of the most impressive skills to have on your resumé.  Take care, be well, and thank you again!


This task is going to make a particularly big headline within our community!