|
-
January 7th, 2010, 04:05 PM
#15
Re: Assigning value to a volatile string
It's certainly true that compile-time checks are always a good thing, and the described usage of the volatile keyword is one means of doing that.
The criticism is that this is the very definition of a hack: You're using a keyword for a purpose completely unrelated to its original intention.
I'd be in favor of that sort of locking_ptr mechanism if there were a keyword which had absolutely no other purpose devoted to it; but co-opting the volatile keyword for that purpose can be confusing to any developer who hasn't been introduced to the technique, so I'd suggest against it.
In regards to the OP's needs: I think a std::queue<std::string> with a read/write lock around it (pthread_rwlock) would be ideal. Use the read lock whenever you call top(), and use the write lock whenever you call push() or pop(). If you're only handling the input on a single thread, or it if you want to ensure that each input is only handled by one thread, then a simple mutex might be more appropriate.
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
|