Sharing of objects across threads ?

V

vivekian

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
 
G

Gianni Mariani

vivekian said:
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).
 
P

Phil Staite

vivekian said:
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? ;-)
 
A

Axter

vivekian said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top