By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

Sharing of objects across threads ?

P: n/a
Trying to write an application in linux where two threads share the
same object ( primarily a double linked list ) . How do i implement
such an object ? Or is there a better way to do this ?

Thanks

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
vivekian wrote:
Trying to write an application in linux where two threads share the
same object ( primarily a double linked list ) . How do i implement
such an object ? Or is there a better way to do this ?


This is not really a question for this group since threads are off topic
here.

However, if your target system had a shared memory model (most machines)
then it's simply a case of making sure that you don't have both threads
calling methods on the list at the same time (including traversal,
object deletion etc).
Nov 22 '05 #2

P: n/a
vivekian wrote:
Trying to write an application in linux where two threads share the
same object ( primarily a double linked list ) . How do i implement
such an object ? Or is there a better way to do this ?


In plain computer science terms you have two choices, build
serialization (locking) into the list manipulators. (insert, delete,
update, traversal) Or use an external lock to control any/all access to
the list.

In real-world terms on Linux it is probably easiest to go the secound
route with std::list and pthreads. Why re-invent the wheel when such
nice, usable wheels are already available? ;-)

Nov 22 '05 #3

P: n/a
vivekian wrote:
Trying to write an application in linux where two threads share the
same object ( primarily a double linked list ) . How do i implement
such an object ? Or is there a better way to do this ?

Thanks


Consider using a synchronized smart pointer like that in the following
link:
http://code.axter.com/sync_ptr.h
http://code.axter.com/sync_ctrl.h

By wrapping your object in the synchronized smart pointer you make your
object synchronize automatically.

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.