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

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.

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

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.

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.

scheme r7rs-large interesting but... is it still in progress? [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 am trying to take a look at the status of r7rs large but I cannot find any information
in scheme reports page, etc, just a talk from 2013. I searched around with google without success as well.
Is it still alive?
Where can I find information?
What would be the tentative date?
What is the progress at this point?
Thanks.
You can read about the R7RS process on the R7RS working group wiki. R7RS-large is listed under the "Working Group 2" section of the front page.
In particular, look through the StandardDocket and ConsentDocket sections. Standard docket is for stuff that's under discussion (and eventual voting). Consent docket is for generally-uncontroversial stuff that's likely to get into R7RS-large without having to be voted on.
There is no firm timeline that I am aware of (though I'm not part of the working group and do not speak for them). The standard docket is quite long, though, and they will have to process through most/all of it before you have anything that you can call R7RS-large.

Test Driven Development is a hoax? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Excuse me for the title a little provocative.I'll take an example. Suppose you need to write a program to build a car. Here's a test program:
public void testCarBuilder()
{
expectedCar=someCar;
actualCar=carFactory.build(bigWhell, yellowBodyCar);
assertEqual(expectedCar, actualCar);
}
To know that to build a car, we need a function that will have the wheels and the carBody as parameter, it should at least have made ​​an analysis of the program. This analysis can be done in natural language, UML or even directly write in the programming language!. We can write this analysis on a piece of paper, leaving it in our brain, or in writing to a file.
Analysis is already a skeleton of a program! So it was always at least one program skeleton write before the test!
Say that development task starts by writing tests is sybyllin, there is always a first skeleton program ( that we can call analysis) to write before. Unless someone shows me how the opposite may be possible.
Of ccourse some people write a test first.
In fact, you just wrote a test first in the question.
Your test has possibly then told you the code you need to write next, but you have discovered that after you wrote the test in the question.
I interpret your question as if you want to know how the design emerges when doing TDD.
In order to write a test you must define some boundary/surface/facade that the test should interact with. This design activity is done up front. The design that grows and changes is the one that is on the other side of that test boundary.
In your (trivial) example, the design that the tests help you discover is the one inside the carFactory. That's not very helpful, so I would say that your test is not that good.
There are different school within TDD. The one I practise advocate that you test from the outside and in. You choose a test boundary that is as close as possible to the system boundary. For instance, you let your test simulate button clicks in the user interface. When doing this, you are free to make changes to the design of the whole system on the other side of that button click.
In your example, why do you want to create a car? What did the user do to trigger this code, and how can the user tell that whatever she wanted to accomplish worked? That's what you should have in your test.

Resources