HI all, Thread support in boost is good. However, 1.- I don't see how to lock a file (fstream) for reading/writing. Do I have to use OS functions? 2.- How do I set a thread to be low priority? Do I have to go to the OS again? I think these are somewhat basic operations. If they are already implemented, can you tell me how to use them. If not, can you tell me if there are plans/steps taken to implement something like 'boost/filesystem/convenience.hpp' (a file with convenience operations). ++Hector C. ---------------------------------- --------------------------------- Yahoo! Mail Bring photos to life! New PhotoMail makes sharing a breeze.
Calderon Hector wrote:
1.- I don't see how to lock a file (fstream) for reading/writing. Do I have to use OS functions?
As far as I know there is no "lockable fstream" class in boost. You should be able to implement it yourself using a mutex. In other words, you can use the fstream as a shared resource and lock the mutex before each read and write. You may want to look into the iostreams library and create a thread_safe_iostream.
2.- How do I set a thread to be low priority? Do I have to go to the OS again?
From old postings I remember the objection to this functionality was cross-platform support. There doesn't seem to be a consistent way to set thread priority across all the OSes supported by boost.thread. However this is only my recollection.
-delfin
comments below:
Delfin Rojas
1.- I don't see how to lock a file (fstream) for reading/writing. Do I have to use OS functions?
As far as I know there is no "lockable fstream" class in boost. You should be able to implement it yourself using a mutex. In other words, you can use the fstream as a shared resource and lock the mutex before each read and write. You may want to look into the iostreams library and create a thread_safe_iostream. I still don't see how this could be done system-wide.
2.- How do I set a thread to be low priority? Do I have to go to the OS again?
From old postings I remember the objection to this functionality was cross-platform support. There doesn't seem to be a consistent way to set thread priority across all the OSes supported by boost.thread. However this is only my recollection.
I think that boost::thread should have functions like hike_up() and slack() that try to change the priority of a thread. They would attempt to change a thread priority. Since it would be only a suggestion (just like string::resize is not mandatory), it would not be a problem for cross-platform support. ++Hector C. PS. Are you implying that boost gods have a policy like "If it doesn't work consistenly for all supported OS, then it's not for boost"? ---------------------------------- --------------------------------- Brings words and photos together (easily) with PhotoMail - it's free and works with Yahoo! Mail.
On 3/1/06, Calderon Hector
I still don't see how this could be done system-wide.
Usually it's up to your operating system, which will prevent opening file for reading if someone's writing or for writing is someone's reading.
I think that boost::thread should have functions like hike_up() and slack() that try to change the priority of a thread. They would attempt to change a thread priority. Since it would be only a suggestion (just like string::resize is not mandatory), it would not be a problem for cross-platform support.
I think you mean reserve, but even reserve is mandatory ( though of course it might reserve more ). A better example would be the inline keyword.
PS. Are you implying that boost gods have a policy like "If it doesn't work consistenly for all supported OS, then it's not for boost"?
Portability requirements * A library's interface must portable and not restricted to a particular compiler or operating system. * A library's implementation must if possible be portable and not restricted to a particular compiler or operating system. If a portable implementation is not possible, non-portable constructions are acceptable if reasonably easy to port to other environments, and implementations are provided for at least two popular operating systems (such as UNIX and Windows). * There is no requirement that a library run on C++ compilers which do not conform to the ISO standard. * There is no requirement that a library run on any particular C++ compiler. Boost contributors often try to ensure their libraries work with popular compilers. The boost/config.hpp configuration header is the preferred mechanism for working around compiler deficiencies. Since there is no absolute way to prove portability, many boost submissions demonstrate practical portability by compiling and executing correctly with two different C++ compilers, often under different operating systems. Otherwise reviewers may disbelieve that porting is in fact practical. from "Boost Library Requirements and Guidelines", http://boost.org/more/lib_guide.htm ~ Scott McMurray
Delfin Rojas
I still don't see how this could be done system-wide.
I don't quite understand what do you mean with "system-wide". Do you mean locking a file across processes? Yep, 'across processes' is a better description than 'system-wide' ---------------------------------- --------------------------------- Yahoo! Mail Bring photos to life! New PhotoMail makes sharing a breeze.
Calderon Hector wrote
Yep, 'across processes' is a better description than 'system-wide'
Well, there is no boost library for synchronization between processes yet. However there is a new library that has just been accepted and it seems to provide inter-process mutexes but I am not familiar with it. You can take a look at the aproval summary at http://lists.boost.org/boost-announce/2006/02/0083.php and go to the previous message in that thread for a link to the library files. Good luck, -delfin
Great. At least I can ensure that my processes won't colide. Since nobody else will be using the files generated by my processes, I'm safe.
Now, I can focus on the second part of my post: How can I lower the priority of a thread created by boost::thread.
Thanks again,
++Hector C.
Delfin Rojas
Yep, 'across processes' is a better description than 'system-wide'
Well, there is no boost library for synchronization between processes yet. However there is a new library that has just been accepted and it seems to provide inter-process mutexes but I am not familiar with it. You can take a look at the aproval summary at http://lists.boost.org/boost-announce/2006/02/0083.php and go to the previous message in that thread for a link to the library files. Good luck, -delfin ---------------------------------- --------------------------------- Brings words and photos together (easily) with PhotoMail - it's free and works with Yahoo! Mail.
"Delfin Rojas"
Calderon Hector wrote:
1.- I don't see how to lock a file (fstream) for reading/writing. Do I have to use OS functions?
As far as I know there is no "lockable fstream" class in boost. You should be able to implement it yourself using a mutex. In other words, you can use the fstream as a shared resource and lock the mutex before each read and write. You may want to look into the iostreams library and create a thread_safe_iostream.
boost::mutex io_mutex; struct synco { synco(std::ostream& os = std::cout) : os(os), lock(io_mutex) {} template <class T> std::ostream& operator<<(T const& x) { return os << x; } std::ostream& os; boost::mutex::scoped_lock lock; }; will allow you to do this: sync(std::cerr) << "hello" << std::endl << "world: " << 3.14159 << std::endl; And guarantee that it will all come out atomically, if all code writing to cerr uses the same protocol. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (4)
-
Calderon Hector
-
David Abrahams
-
Delfin Rojas
-
me22