Roman Roth
Roman Roth

Reputation: 31

What is the Boost equivalent of a HANDLE?

As the title states - what is the Boost equivalent to a Windows HANDLE? I need to port some Windows specific code to Linux/OS-unspecific and it uses handles and their Functions (e.g. CloseHandle).

If the eqivalent is a boost::mutex, then why, and what is the difference between a Windows HANDLE and CRITICALSECTION?

I've loked for it in the boost documentation but I can't seem to find it. Any help appreciated!

Upvotes: 0

Views: 205

Answers (1)

MSalters
MSalters

Reputation: 180235

There is no equivalent. HANDLE is a handle to a Windows kernel object.

That also makes it easy to explain the difference with a CRITICAL_SECTION. A Windows critical section is a non-kernel object; it only applies to your current process. That's similar to std::mutex. On Windows, CreateMutex creates a mutex object which is a kernel object that can be named, secured and shared between processes. That's why CreateMutex returns a HANDLE.

Note that CreateFile also returns a HANDLE. Just like mutexes, files can be named, secured, and shared between applications.

You will therefore need to find the true type of each HANDLE in your process, and replace it on a case-by-case basis.

BTW, we've got std::mutex, no need for boost::mutex. But boost::interprocess::interprocess_mutex is still relevant as it's the equivalent of a Windows kernel mutex.

Upvotes: 1

Related Questions