what are windows synchronization routines other than critical_section? [closed] - winapi

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am reading through the msdn articles about windows synchronization. It is really good & thorough material. At the same time is very time consuming. I am more interested in a quick comprehensive guide on the same topic. Any pointers?

This is a list of the concepts that I use in my native (unmanaged, Win32) application. I've added some relevant function names between parenthesis):
CriticalSection (InitializeCriticalSection, TryEnterCriticalSection, LeaveCriticalSection, ...)
Mutex (CreateMutex, WaitForsingleObject, ReleaseMutex, CloseHandle, ...)
Semaphore (CreateSemaphore, WaitForSingleObject, ReleaseSemaphore, CloseHandle, ...)
Event (CreateEvent, SetEvent, ResetEvent, WaitForSingleObject, CloseHandle, ...)
Besides these you could also use a file to implement locking (e.g. between processes running on different machines):
Simply create the file using CreateFile, use FILE_FLAG_DELETE_ON_CLOSE, and don't specify any of the sharing flags.
If a process already created the file, the CreateFile will fail.
To unlock, close the file using CloseHandle.

This might be a good starting point:
Synchronization Functions: http://msdn.microsoft.com/en-us/library/ms686360%28v=VS.85%29.aspx

Related

Golang Ctx WIthTimeOut in Clojure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In clojure concurrency, I would like the thread that I spawn kill itself if it take to long to do it's task, similar to what Golang ctx withtimeout provide. how should i do it?
Mind you I dont have any knowledge of java thread.
You can't kill a Java thread cleanly, so people usually write very long-running threads to check a flag occasionally, and keep working only if appropriate.
On the other hand, a thread's client can stop waiting for an answer. If you start the thread with future, you can use the timeout parameter on deref at https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/deref, or check on it with future-done?.
When you have a lot of async stuff going on, the better Go-like algebra in Clojure's core.async library can be helpful (https://clojure.github.io/core.async/) as an alternative to raw Java threads.
never mind, apparently there is something called future and promise..

WINDOWS API: GetCurrentThread(); in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I just started my college "adventures", and one of them is subject called operating systems. I must admit that the subject is the most boring ever. Last week, we got our first homework, and i do not know what to do as this is the first time ever i come up with Windows API functions or this topic in general. The task is very simple, we need to write very basic code in C that shows how does GetCurrentThread() work!!!???? I tried looking for solution online, but I could not find anything and our professor is not doing anything to help us. I found the use of functions like GetCurrentThreadID() but that is not what i need. Can somebody write simple program ( 20-30 lines of code ) which contains the use of this function (in C)?
Operating systems courses tend to suck because they take the simplest of concepts and try to make them convoluted.
Documentation for the GetCurrentThread () function is
https://learn.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentthread
What it does not explain is that the return value for the function is a "handle." Windoze uses handles somewhat as pointers to objects but where you cannot access the object directly.
So you call GetCurrent() thread and it returns a "Handle to the Thread." That handle can then be used to do things with the thread.
Here are the things you can do:
https://learn.microsoft.com/en-us/windows/desktop/ProcThread/process-and-thread-functions
Some of these function pages have short examples.
So you could do:
print ("Thread ID: %d\n", GetThreadID (GetCurrentThread())) ;
and have the ID of the current thread.

Implementing redis in go [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying implement redis basic functionality like below in Go.
GET
SET
ZADD
ZCARD
ZCOUNT
ZRANGE
SAVE
If you want to implement a Go server offering some Redis features, it is quite easy. You need to decide about the goroutine model, then implement/reuse some data structures (map and skiplist), then implement the Redis protocol (which is simple enough).
I would suggest a goroutine model with 2 goroutines per client connection, plus one goroutine to implement the Redis engine and manage the data structures. The benefit of this model is you can easily support pipelining and the atomicity property of Redis commands without any explicit locking. This model is well adapted if you want to later extend the scope by supporting blocking commands (such as the ones useful for queues).
Now, if you also want to mimic the same exact Redis behavior, this is more complex. Especially, saving the data in background leveraging the OS copy-on-write mechanism will be difficult with Go (since forking does not work). For a memory database, foreground saving is always easy. Background saving is extremely difficult.
You may also want to have a look at the following attempts, and simplify/enrich them to match your goals:
https://github.com/siddontang/ledisdb
https://github.com/felixge/go-redis
https://github.com/docker/go-redis-server

How to tell when the debugger is lying to you [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please take a look at my recent question here: Deadlock with no user code
How can you tell when the debugger is lying to you in this way? Other than, of course, showing that what it is telling you is impossible?
I don't like relying on that since I've seen so many 'impossible' states in a program that were in fact happening due to some subtle or esoteric problem.
Yes, those are pretty wacky stack traces, particularly the 1st one. Hard to theorize how that happened. It doesn't usually get that screwed up unless you debug optimized code.
Which is hint #1, never trust what the debugger tells you when you have to debug release built code. Strongly avoid it, you don't always have the luxury when you need to troubleshoot a deadlock however.
Strong hint #2 is paying attention to the code-flow. The normal one for a blocked thread, bottom to top in the Call Stack window, is yourcode => runtime (msvr120) => winapi layer (kernel32 et al) => native api (ntdll.dll). This is generally the case, there are a few cases where this flow is reversed, callbacks from the OS into your code, like window notification, thread-start (always at the far bottom of the stack for example), I/O completion.
Which is what's wacky, there is no realistic scenario where a low-level native api function like ZwWaitForSingleObject() could ever directly call into the C runtime library. That's bogus, only the top entry (Block) could be accurate. Yes, tough debugging that way.

What is the difference between Ntxxx and ZWxxx? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I tried to find the usage of NtqueryDirectoryFile() function.
http://msdn.microsoft.com/en-us/library/windows/hardware/ff556633%28v=vs.85%29.aspx
I refered the above link for this. But, They mentioned about Zwxxx (). I couldn't understand Ntxx and ZWxxx. Can anyone explain about this.
Basically Zw functions are equivalent of Nt functions except they don't do security checks, so are used inside kernel mode only, to avoid the performance penalty.
You can only call Nt functions from user mode, through ntdll.dll. As Michael pointed out Zw functions are just mnemonics to Nt counterparts in user mode.
#Adriano provided a nice link: http://msdn.microsoft.com/en-us/library/windows/hardware/ff565438(v=vs.85).aspx

Resources