|
-
May 20th, 2009, 04:33 AM
#7
Re: C++ - Using STL queue dumps core
I have written my own message queues (prodcon_queue) for multi-threaded systems but it is fairly complex. I had to write a mutex wrapper and a condition variable wrapper.
boost may have one though that suits your needs. thread-safe collections is something they have added in the last few years.
As for your OBJ class, there are things in it that could be improved but it looks like a prototype anyway as you have called your members A, B and C and then in your constructor you gave them real names so I guess you are copying here a subset of what you are actually doing.
Please make your code const-correct too.
Beware of returning const char * from your get methods as you have used c_str(). These pointers only have the lifetime of the strings they come from and then only if the strings are not modified at any time. Unless you know that it is performance critical then it is better to return a std::string. Actually I have a portable_string class that uses reference-counting for long strings (longer than 16 characters) and is immutable other than assignment. The reference-counting can be made atomic so is thread-safe.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|