LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2010, 09:05 AM   #1
vlyamtse
Member
 
Registered: Apr 2007
Posts: 54

Rep: Reputation: 15
some concurrency questions about shared libs


Hi all,
Can shared library be loaded by several processes simultaneously without synchronization of code?
Here's the specific scenario: the method in the shared lib is likely to be called from any of the several processes and the method performs file IO. Does the method have to be protected with critical section, or does the process creates own independent "copy" when shared lib is loaded to memory?
What kind of objects should be used to protect the "shared" file in this scenario?
Thanks,
-V
 
Old 09-27-2010, 10:01 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
A shared lib will act as if every process using it has its own independent copy of everything in the shared lib.

Any part of the shared lib for which independent copies would be required for correct behavior will actually have independent copies.

Only parts for which the behavior would be the same for shared vs. copied will actually be shared.

So you don't need to add any critical sections etc. to manage such sharing.

BUT, if multiple processes are doing file I/O to the same files, you do need to manage that. That fact is completely independent of whether or not that file I/O occurs in a shared lib (so the code to do the file I/O is shared).

So your situation might require some synchronization (critical sections or other methods) to manage the file access, even though it doesn't need any for the use of the .so.

Last edited by johnsfine; 09-27-2010 at 10:04 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using shared libs hwoarang Programming 7 08-20-2008 02:09 PM
shared libs help spatula Linux - Software 3 12-14-2005 03:48 AM
Recompile ALL shared libs? ta0kira Programming 3 06-13-2005 12:49 AM
Qt Libs Static or Shared magicm Slackware 2 10-15-2003 05:05 AM
shared libs hanzerik Linux From Scratch 2 03-14-2002 01:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration