Golang Ctx WIthTimeOut in Clojure [closed] - go

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..

Related

keyword "go" in golang, whether go is a atomic operation? [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 1 year ago.
Improve this question
in go programing, we always create a go routine like
go func(){}
i want to know whether keyword "go" is an atomic operation, what if create a go routine fail by this operation.
can i monitor a new go routine created success or not?
Or maybe this keyword "go" create a routine that will never fail.
The spec says nothing about failure to create the goroutine or invoke the function, so behavior at this point is up to the implementation and there is no defined way to determine success or failure.
The kinds of errors you would encounter on goroutine creation will be fatal errors (likely due to resource exhaustion), not something that can be caught and handled gracefully. This is similar to the kinds of errors you would encounter on invoking a function.

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

Ruby Custom Classes, How do you know what to initialize? [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'm trying to write a small dictionary Ruby app where I can look up existing entries, add and remove entries (ALL ENTRIES ARE PUT INTO A HASH). So right now I'm creating a Dictionary class and I'm not quite sure what exactly should be 'initialized' method.
I'm still pretty new to Ruby, so if someone could explain what should be initialized at the beginning of a class I'd be extremely grateful.
How do you know what to initialize?
Time and experience. In general, #new should:
Initialize instance variables.
Configure any object defaults.
Register itself with observers.
Housekeeping tasks needed to reach a minimal "ready" state.
Sometimes an object needs to do a lot more work to be "ready" (whatever that means for your class), and #new can just as easily do too little as too much. Finding the right balance for your application is what matters, so feel free to open new questions here or on Code Review Stack Exchange with more concrete questions and some actual code.

what are windows synchronization routines other than critical_section? [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 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

Resources