Win32 API Method SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1) is thread-safe or not?
Do you mean thread-safe? If so, yes, I believe it is.
SetProcessWorkingSetSize is threadsafe. The setting are done at the process level and are thread safe.
Related
I was wondering if calling Write() on an os.File is thread safe. I'm having a hard time finding any mention of thread safety in the docs.
The convention (at least for the standard library) is the following: No function/method is safe for concurrent use unless explicitly stated (or obvious from the context).
It is not safe to write concurrently to an os.File via Write() without external synchronization.
After browsing the source code a little bit I found the following method which is eventually called by file.Write(). Since there are race condition checks in place, I'm assuming that the call is in fact not thread-safe within Go (Source).
However, it seemed unlikely that those system calls wouldn't be thread-safe on an OS level. After some browsing I came upon this interesting answer that fueled my suspicions even more. For windows the source indicates a call to WriteFile which also appears to be thread safe.
Multiple threads in my application will be calling MultiByteToWideChar for converting UTF-8 to wchar_t strings.
I've been unable to find any documentation which states whether this function is re-entrant or thread safe. I want to avoid synchronizing calls to this method if not needed. Does anyone know the answer or how to find it?
The function is thread safe ... but I don't have a definitive link to prove it!
There is some discussion on this thread ... but in general the rule would be that if an API call does not have some specific context (eg. a handle) it is called with or other explicit threading rules (ie. the whole GDI layer) then it should be thread safe.
It would certainly be good to see this more explicitly called out in the documentation though.
is there any kind of semaphore for processes in Windows API? I found this one
but it is only for thread as I understood, thanks in advance for any help
Look at the the help for CreateSemaphore() function:
http://msdn.microsoft.com/en-us/library/ms682438(v=VS.85).aspx
in the Remarks section, starting from "Multiple processes can handles....".
You'll find 3 cases there - all of them useful.
Use CreateSemaphore or CreateSemaphoreEx to create a named semaphore. You can use the name to access the semaphore from other locations by calling CreateSemaphore a second time.
I'm wondering if ucnv_convertEx in ICU library is thread safe. Looking at source it seems that it is thread-safe, but I'm not 100% sure. Also I can not find explicit state of this in ICU documentation.
Thanks
The ICU User Guide discusses this, for all objects that have an open/close model. Each Converter object must be used in a single thread at a time. If you need more of them, clone them. They're cheap to clone.
By the way, where would you have expected this information? Maybe you could file a ticket, and we can improve the documentation. Thanks.
Basically ICU is thread safe, but:
You can't assume that is safe to call const member functions/functions operating on it of same object from different threads (in fact this is generally unsafe which makes ICU tricky in all thread related aspects)
Of course you can't use same object with non-cost member function/functions working on object from different threads.
Basically in case of ucnv_convertEx as long as you don't share UConverter between threads it is safe.
I am looking for a simple way to read/write a file asynchronously using Win API. What I had is mind is something like the asynchronous winsock API (WSAxxx) completion routines. However the file API doesn't seem to have those. Are they hidden somewhere?
Waiting on the overlapped events in a seperate thread adds thread management overhead, not to mention there either needs to be a thread-per-file, or the 64 objects problem needs to be faced. Completion ports is an overkill. Reading the file synchronously on a seperate thread is irrelevant.
Any suggestions?
CreateFile and ReadFile/WriteFile functions support so-called 'overlapped' mode which is what you need. There' also ReadFileEx/WriteFileEx that work in async mode only.
In short, you need to open file with FILE_FLAG_OVERLAPPED flag and pass OVERLAPPED structure (and callback in case of xxxEx operations) to file access functions.
Here's a sample class for using it.
I know that in .net it's possible. What I don't know is to which win32 functions it maps
As soon as you step into the async territory you should forget the word "easiest"
Seriously, the easiest would be to use .NET's System.IO.FileStream with isAsync=true in constructor and BeginRead/EndRead methods.