|
led mike wrote: mohamedmrc wrote:
thinks
Indeed, give that a try.
It'll never catch on.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
If I have a quantity of unmanaged code (in C, designed for another system), and most of it could be safely terminated at any time but it makes callbacks into managed code which could not be so terminated, would it be safe to do something like:
volatile int statflag;
if (Exchange(&statflag, 1) == 0)
{
call_managed_code();
if (Exchange(&statflag, 0) != 1))
terminate();
}
else
terminate();
' In the other thread...
If Threading.Interlocked.Exchange(safeflag, 2) = 0 Then
TheThread.Terminate
If the portion of the code which is in C never does anything that could not be safely stopped asynchronously while safeflag is one, would there be any danger in calling Terminate() upon such a thread? Obviously any resources that had been allocated by that thread would have to be freed elsewhere, but in this particular application I'm not expecting the unmanaged code to use only resources that are given to it by other code (which could then take care of any necessary de-allocation).
In the particular application, there is a risk that the C portion of the code could hang without any callbacks to the managed portion, so I'd like to be able to use something more "potent" than Thread.Interrupt; is Thread.Terminate safe if used only upon a thread which is known not to hold any locks or be manipulating any other dangerous constructs?
|
|
|
|
|
supercat9 wrote: would there be any danger in calling Terminate() upon such a thread?
Hi again, welcome to CodeProject. Let me just warn you that many of the regular members here will tend to flame on people who are obviously not reading the documentation.
TerminateThread[^]
TerminateThread is a dangerous function that should only be used in the most extreme cases.
Terminating threads is never considered Best Practice. On the other hand if you have no other choice then it really doesn't matter what dangers might exist. Obviously, if you do have another choice then go with the other choice.
|
|
|
|
|
Hi again, welcome to CodeProject. Let me just warn you that many of the regular members here will tend to flame on people who are obviously not reading the documentation.
It states that it is a dangerous function that should only be used in extreme cases. I can certainly appreciate that many bad things can happen if it is done on managed code or code which uses the Windows API. My situation is a bit different from the usual one, though, and I was wondering whether anyone had done anything similar.
I'm writing code for a microcontroller with a few kbytes of RAM and a few dozen kbytes of code. For testing purposes, I would like to be able to run the code on a Windows machine, replacing the physical I/O routines with calls to wrapper functions which would call back into managed code that would simulate the I/O in question. If every call to a wrapper function checks for a "terminate, please" flag, then any loop which calls any of the wrapper functions will exit once the flag in question is set, but there's no guarantee of when that will actually take place. If something goes wrong in the target system code, such callbacks might never take place.
Since the target application shouldn't get stuck in such a loop, it probably wouldn't be the end of the world to require that someone use ctrl-alt-del and kill the non-responsive application, but that would seem more dangerous than having the application terminate the stuck thread, especially since the application might be doing things on other threads that should not be blindly terminated.
|
|
|
|
|
supercat9 wrote: For testing purposes
For testing I would think as long as you can accomplish the testing goals you wouldn't care about the dangers. I imagine the author talking about dangers is addressing production software environments.
|
|
|
|
|
I imagine the author talking about dangers is addressing production software environments.
The system might get used in something between a testing and production environment; the actual hardware device includes the ability to initiate TCP connections to a server, and it's possible that customers might use the "simulator" to simulate having a number of devices connecting to the server at once. By the time the code gets to the customer it shouldn't get into bad situations, but in case something bad happens (e.g. the server comes back with a response that would confuse the device) it would be nicer to allow a controlled shutdown of the thread than to force the user to kill the application.
I guess my main question should perhaps have been better phrased as, "The documentation says to avoid using TerminateThread; is there any accepted style for wrapping it in those circumstances where its use may be reasonably safe and appropriate?" I guess if there's no way to recover the stack in older versions of Windows that would be bad, but it could still be better than having a stuck thread gobble up all the CPU time it can get.
On a related note, under what circumstances is an "isBackground" thread killed off blindly when an application terminates? If a thread is doing a "WriteAllText" to create and write a file, is the function guaranteed to either fail altogether or succeed completely in case of application termination, or should it be surrounded by saving the isBackground property of the current thread, setting it to False, performing the function, and restoring the old value of isBackground?
In any case, thanks for responding. -- John
|
|
|
|
|
supercat9 wrote: under what circumstances is an "isBackground" thread killed off blindly
AFAIK it always is. Therefore it is a bad idea to use a background thread for writing files and databases.
|
|
|
|
|
supercat9 wrote: "The documentation says to avoid using TerminateThread;
Well I thought I already covered this but let's have another go.
led mike wrote: Terminating threads is never considered Best Practice. On the other hand if you have no other choice then it really doesn't matter what dangers might exist. Obviously, if you do have another choice then go with the other choice.
What it comes down to is if you can accomplish what is needed without terminating threads (stop the thread gracefully), do it that way, always, period. However if for some reason terminating threads is all you can do and you must do it, then it doesn't matter if there are dangers does it?
Now to me that seems like a pretty simple concept. However you seem to be thinking along another line that I have so far failed to understand.
|
|
|
|
|
hi, i have a question about my way of programming
if i want to make a program i start with a skeleton and start with
nothing, if i dont know something lets say winsock i go look for sample programs, i start look what each line of code does and what its for and
start recoding to use it in my program.further a long the way i find it easier to go on.
when something isn't working, even if it take me a month i go on til it does work.although i don't know why(because i don't really know how it al works)it doesn't work, i kind of know it but its just like its a littly foggy.
for example i was once working on a program and there was a error somewhere in my code,the whole time i knew wich lines maybe causing the problem
but it took me a month befor i tried it.
and when i want to make a program i will get it done so my question is
am i a programmer or should i stop with its more like a hobby because my education is to low and i want it so bad to be a freelance programmer.
i tried several languages vc++ html css php mysql and now in win32 assembly.
thanks in advance
3 things
1 maybe i am contradicting myself: so what, don't apply to my message i, don't need answer from
arrogant people who think they know how someone is, by reading their letter.
2 i had to learn all of it in english so that makes it a little harder, it's not my language.
i don't had a high adducation what you need for programming so i learned it all by myself
so doesn't that say something for me ?
3 please only answer if you can leave me in my value
for all those people who can please reply
sorry for my poor english but i am sure that it is understandable
thanks for the reactions, and im not giving it up here is where my hart lies and i keep learning.
i know what a pointer is etc. but my problems are that there isn't a good book in my language
and the absence of someone to ask things, most books say how a function works what regs and/or flags
it affects but i can't ask what can we do with the changed flags this is just an example,what i mean is the questions i have i can't ask in programmer groups, the answer i offen get is i have to read more books but the books don't have the answers to the questions i have.
modified on Wednesday, April 15, 2009 1:24 PM
|
|
|
|
|
Your are a hobbist. This does not mean you are not able to become a better programmer, but for the question itself, you are unsure.
My question is: Do you like programming? Are you thinking about giving up this area?
|
|
|
|
|
Paulo Zemek wrote: Your are a hobbist.
If you meant "you're" as in "you are" a hobbist, really? So he is one of these?
hobbist
One entry found.
Main Entry:
Hob·bism Listen to the pronunciation of Hobbism
Pronunciation:
\ˈhä-ˌbi-zəm\
Function:
noun
Date:
1691
: the philosophical system of Thomas Hobbes ; especially : the Hobbesian theory that
people have a fundamental right to self-preservation and to pursue selfish aims but
will relinquish these rights to an absolute monarch in the interest of common safety
and happiness
|
|
|
|
|
That reply was as unhelpful and arrogant and generally evil-spirited as this one is from me. Only my target is you, and unlike you he did *nothing* to invite such treatment.
|
|
|
|
|
dojohansen wrote: he did *nothing* to invite such treatment.
Nothing? Really? What about where he posted "your" for "you are" and "hobbist" for "hobbyist", which is all I pointed out, and yet somehow you think this qualifies as "evil-spirited". What a retard.
Frakoff icehole.
|
|
|
|
|
Yeah, people who make accidental spelling mistakes are really asking for it. Lay it on them.
I wouldn't have bothered commenting if it weren't for the fact that I noticed it was you and I had been reading forum posts for a while and your name kept popping up next to unhelpful and condescending posts over and over again. At first I thought I'd just stay above that, but after a while I thought "damn, I think this is the tenth mean posting by this dude and I've yet to see him contribute anything constructive. To hell with normal standards of conduct - he's not worthy".
Obviously you're unlikely to even stop a second and ask yourself if there may be a grain of truth in my criticism, but just maybe someone else will think "you know what, he's right - I'm going to watch myself so I don't start behaving like this led mike dude". And if so, the world will be a (slightly) better place.
Feel free to further demonstrate your intellectual powers/emotional maturity by emitting more of the frakoff icehole stuff, it'll be the highlight of my day.
|
|
|
|
|
dojohansen wrote: Lay it on them.
Yeah, I really laid into that guy by posting the definition of the word he mistakenly posted. Have you lived an exceptionally sheltered life?
dojohansen wrote: I've yet to see him contribute anything constructive.
Well by all means, you must the authority on everything I have done then. Game over.
dojohansen wrote: Obviously you're unlikely to even stop a second and ask yourself if there may be a grain of truth in my criticism
I don't need to, I know it's true.
dojohansen wrote: I'm going to watch myself so I don't start behaving like this led mike dude"
Please, give it a try, you might find that I just make it look easy.
dojohansen wrote: Feel free to further demonstrate your intellectual powers/emotional maturity by emitting more of the frakoff icehole stuff, it'll be the highlight of my day.
I will probably regret this but text is cheap. First I don't owe you or anyone else any explanation, however on the off chance you are posting all your drivel because you are actually interested, here goes.
You might notice that I have helped many people on this site for the entire time I have been here if you bother to look at my profile and match up my start date with my MVP awards. When I first started encountering these idiots that come to this site I was like everyone else and attempted to offer polite assistance. After a while it was obvious that polite assistance was not getting through to them. Then while laughing at one of these morons post one day I typed in my humorous thoughts. The response to the post was overwhelming. I decided to try more of this. In a short time it was obvious that, at the very least, these monkeys actually read these types of posts rather than just ignoring them. In some rare cases it has even helped them to see there failed perspective on the work they are doing.
Anyway, since there was small successes and they are sometimes humorous, I generally go that way. However I do mix in an occasional normal reply just to make sure I don't forget how.
Ok, that's the short version. Since you likely just decided to have a go at me I don't imagine this will change that so, you're up, flame away.
|
|
|
|
|
led mike wrote: Ok, that's the short version. Since you likely just decided to have a go at me I don't imagine this will change that so, you're up, flame away.
Thanks for that, and no thanks, I've no desire to flame.
I'm not sure I share your belief in the efficacy of your "technique", but I'd like to believe that you really have a constructive intent, however well hidden it may be (to me at least). So I'll just take your word for it. I do think that attacking people specifically for spelling or grammar errors is a bit unfair though. I may be mistaken, but I'm under the impression that codeproject isn't a US-specific community, and while I obviously realize it's in my own best interest to post in English rather than my native Norwegian or my current host culture's French I think those who make an effort to use your language do not deserve ridicule and harassment for nothing more than using it imperfectly.
Those who post to ask others basically to just do the work for them may deserve a bit of a kick though, so maybe you can reserve this particular talent of yours for them. Just a suggestion.
|
|
|
|
|
dojohansen wrote: I'm not sure I share your belief in the efficacy of your "technique"
It seems you do share it since it's doubtful.
dojohansen wrote: but I'd like to believe that you really have a constructive intent
It is the primary reason I spend any time on this site. I may do digress time to time.
dojohansen wrote: I do think that attacking people specifically for spelling or grammar errors is a bit unfair though. I may be mistaken
Nah, you're not mistaken, I just didn't really consider it an attack, more like a jab or dig. And I specifically didn't recognize that poster as non english. I do agree with you and normally don't comment on typo or language issues other than leet or text speak.
dojohansen wrote: Those who post to ask others basically to just do the work for them may deserve a bit of a kick though, so maybe you can reserve this particular talent of yours for them. Just a suggestion.
Thank you, that's a good suggestion. Also your sincerity surprises me, it seems my reply was worth the effort. Feel free to reign me in anytime.
|
|
|
|
|
rilm wrote: i start with a skeleton and start with
nothing
Apparently you start with a contradiction.
That's enough for me, I'm not reading any more of it. Good luck.
|
|
|
|
|
|
rilm wrote: if i dont know something lets say winsock i go look for sample programs, i start look what each line of code does and what its for and
start recoding to use it in my program.further a long the way i find it easier to go on.
That's called research. Always a good idea to do your homework and be prepared
rilm wrote: when something isn't working, even if it take me a month i go on til it does work.
That's called perseverance. Sounds like your trying hard to learn it, but are still having a hard time with efficiency. That, like most other necessary skills, can be learned. Not only in school, but also through books, video's, tutorials and sites like this one.
It will be expensive though, if you don't produce any code during an entire month. Then again, sometimes you may be able to fix things without coding, or with a minimum of it.
rilm wrote: am i a programmer or should i stop with its more like a hobby because my education is to low and i want it so bad to be a freelance programmer.
You are also a programmer when it's a hobby. Getting paid for it doesn't make you a programmer, writing code does. Even if you keep it as a hobby, if you are passionate obsessive enough you'll keep writing code, which in turn is practice, which in turn may lead to enough knowledge to impress a potential boss. A paid programming-job would be a good place to get experience in coding.
Once you consider yourself skilled enough, you might want to consider taking some additional courses in sales and marketing.
rilm wrote: i tried several languages vc++ html css php mysql and now in win32 assembly.
What language would be the most-asked for in a freelance programmer?
I are troll
|
|
|
|
|
If you have Logics.If you think and if you have some ideas.
if you can try to do something new.
That means you are a programmer.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
May I give my two cents?
You are clearly not enjoying coding, otherwise you would not contradict yourself in almost every statement. You see a potential way out of your current life situation in technology, and believe that coding is the way to go.
Ask yourself this, and use your Internet connectivity to expand your answers:
WHat is it that you really like to do for the rest of your life? If you answered programming, what is your second choice? and your third?
Now, what is common among those three? And what do you have in your personality that will fit into each one?
You may find out that by moving down to your other choices, you can make yourself fit in better. Coding may look simple, but as you have found out, sometimes it is not. It takes not only perseverance, but also productivity, two things that are compeltely contradictory unless you are willing to devote yourself fully to it. It does not matter how many days/months/years/decades of experience you have, as unless you push yourself to the next level, with the same problem f productivity/perseverance, you will not enjoy it.
And whatever you decide to do, learn to do one thing well, and that is to communicate well. More than finding bugs, or coding in assembler, you will be compensated by your ability to communicate with all around you.
|
|
|
|
|
I have to say I think this is romanticized bullshit. Sorry to be so blunt, but I do. There is no requirement that you enjoy coding in order to be successful at it. As with *any* job, if you enjoy it that's good, because you'll spend an awful lot of time on the job, but in fact you may enjoy a job and be awful at it or you may dislike it and be really good at it.
So as always it comes down to choosing among alternatives, paying the opportunity cost of not doing alternative A and do B, or vice versa. And in that big equation job enjoyment is an important variable but far from the only one. If you have a sh*t job you hate that pays badly and you can switch to a boring-ass job that pays well it's worth thinking about it.
I'm sure this will invite a lot of emails from people who think personal experience is some sort of proof for anything, but I doubt *anyone* will be able to present any solid proof that there's anything more than a vague correlation between being happy at work and being successful.
|
|
|
|
|
Based on how you describe your approach I would say that you're probably not what I would call a programmer. If you *understand* any of the stuff you're copying from around the web then perhaps you will some day become a programmer, but as long as you are simply stubborn and copying various things you find online until something appears to do something similar to what you wanted that doesn't really count.
I do however salute your ambition and curiosity and figure there is no reason why you cannot become a programmer. You should consider a different approach though - learning by doing is great, but it's much more powerful if combined with theoretical studies. Buy some books or at least bookmark good articles that are NOT hands-on labs or tutorials but theoretical treatments on computer science subjects. What exactly you wish to learn is really up to you, all have their use but few are essential. I personally enjoyed learning how computer hardware works and understand the many layers of abstraction piled on top of that, but then again it's perfectly possible to learn OOP and make excellent use of it without knowing about stack-based programming or even know what a pointer is. That, after all, is the whole point with all this abstraction: To make it completely unnecessary to deal with the low-level detail.
Using the internet and either using other people's code or at least being heavily inspired by it is simply part of any efficient programmer's toolkit nowadays. It's not in itself any sign of lack of ability. So what really matters is to understand. Also, few developers are as good at taking a long term view when designing technical solutions as they ought to be, and this is an area where anyone who decides to be conscious about this can gain a strategic competitive advantage, because it often isn't very complex but just gets overlooked.
Good luck!
|
|
|
|
|
If you write code, you are (by definition) a programmer. You aren't necessarily a great programmer, but that comes with practice, perserverance and a whole heap of skill. Nearly everybody here, will have learned from others - so, learning from others code isn't necessarily a bad thing. The only thing you need to watch out for, is that you don't learn BAD coding habits from substandard applications.
When I started writing MFC code back in 92, I couldn't get my head round it. I bought a Que book, and spent months figuring out what the code did - a lot of time was spent just watching variables as I stepped over sections of code, but I emerged a stronger coder. When I wanted to learn WPF, I read a lot of stuff, didn't understand a lot of it, but I perservered with it. Now I'm a member of a group called the WPF Disciples, which has some scarily clever guys in it - that's because of perserverance.
Bottom line - stick at it if you enjoy it. Don't set your sites too high too early otherwise you'll end up disheartened, and less likely to stick at it.
Good luck.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|