|
Can you please tell me now how all this relates to my question? I have seen posts like the one you linked
|
|
|
|
|
I don't see the need for locking on a static method unless it accesses class-information or a shared unmanaged resource.
Also, adding "lock" everywhere feels like an on error resume tactic
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
you mean locks in HASP class or locks in function1/2?
in function1/2 I added because it can be function1 called read, then function2 called read and write - now function1 calls write - will the output be what I expected? depends on the HASP device.
|
|
|
|
|
Member 12061600 wrote: will the output be what I expected? Yes, as the read would have to finish before something else can be done with the port.
Which HASP dongle are you using? Don't they go by the name "sentinel" these days?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What kind of serial device requires a read, THEN a write?
|
|
|
|
|
Maybe he's writing code for the server side?
|
|
|
|
|
But what he's got looks like "slave" code; usually in firmware.
The master does the broadcasting (i.e. write) and then expects / awaits an answer (read).
|
|
|
|
|
Right; that's what I meant by "server".
|
|
|
|
|
Fair enough ... just never used serial com in a "client-server" setup; only master-slave.
For example, a printer only prints when you tell it to; it doesn't ask for something to print (usually).
A scale tells you the weight only when you ask.
etc.
|
|
|
|
|
Potato / potatoe.
One of the first serial devices I wrote software to communicate with was actually a fairly large specialized computer that performed analyses of gasses.
But most serial devices I encountered were smaller, e.g. a coin counting machine, a magnetic card encoder. Good times.
|
|
|
|
|
But I still don't know if OP is writing client code or server code ...
|
|
|
|
|
Can we at least agree he's writing bad code?
I expect the examples he posted are just for reference and shouldn't be taken literally.
|
|
|
|
|
hipotethical - its not important in reality it could be other way round(first write then read), but my question still holds.
|
|
|
|
|
Hypothetically then, I see deadlocks.
|
|
|
|
|
So can you please explain to me how and why you see deadlocks?
|
|
|
|
|
I don't deal in hypotheticals.
|
|
|
|
|
assume it is first write then read. I can't recall the protocol. But why does it matter for the thread safety? I gave all the information.
The principle remains: function1 and function2 have their code locked.
HASP class has read and write locked too.(with a different lock though).
|
|
|
|
|
It seems OK for what you describe, but I doubt that your HASPclass should be static; that seems like a poor design.
Oh, and I would expect Initialize to be public and DoInitialize to be private . Or maybe what you have as DoInitialize should be named Open or Connect ?
modified 5-Feb-16 22:04pm.
|
|
|
|
|
yeah openport or smth like that is better name.
why HASPclass being static is bad idea?
|
|
|
|
|
Because you can't guarantee that you will never need more than one.
|
|
|
|
|
I will find out if I need acess to more than one port. Other than that is my setup ok?
|
|
|
|
|
Quote: I will find out if I need acess to more than one port
It's not just about what you need right now; it's about what anyone might need any time in the future.
Consider the possibility that you will write an article about it here on CP, and five years from now someone wants to use it, but needs to access multiple ports. And it may not only be HASP; perhaps someone wants to use your code for other types ports.
Do not limit the flexibility of your code unless you have a very good reason to do so. "I don't need it right now" is not a good reason.
Quote: Other than that is my setup ok?
I can't make a judgement on that.
|
|
|
|
|
No I mean my original question the HASP class and how I use it in function1 and function2 is it thread safe? that is what I meant. Some people comment here they see deadlocks. and I am confused.
|
|
|
|
|
Message Closed
-- modified 5-Feb-16 4:55am.
|
|
|
|
|
If, by this, you mean can you create a Kiosk using C# then yes you can. Microsoft even publish a sample[^] to show you how to do this.
This space for rent
|
|
|
|