Click here to Skip to main content
15,914,163 members
Home / Discussions / C#
   

C#

 
Questionhow to write string in PDF Pin
wasimsharp15-Apr-09 1:10
wasimsharp15-Apr-09 1:10 
AnswerRe: how to write string in PDF Pin
stancrm15-Apr-09 1:18
stancrm15-Apr-09 1:18 
GeneralRe: how to write string in PDF Pin
wasimsharp15-Apr-09 18:23
wasimsharp15-Apr-09 18:23 
AnswerRe: how to write string in PDF Pin
tom57200715-Apr-09 2:56
tom57200715-Apr-09 2:56 
Questionmultithreading: lock (static) function library Pin
rpm820015-Apr-09 0:58
rpm820015-Apr-09 0:58 
AnswerRe: multithreading: lock (static) function library Pin
Moreno Airoldi15-Apr-09 3:22
Moreno Airoldi15-Apr-09 3:22 
AnswerRe: multithreading: lock (static) function library Pin
PIEBALDconsult15-Apr-09 6:29
mvePIEBALDconsult15-Apr-09 6:29 
GeneralRe: multithreading: lock (static) function library Pin
rpm820015-Apr-09 22:56
rpm820015-Apr-09 22:56 
First of all: Thank you both for your replies on that subject.

I think I am a bit closer to finally solving my problems with semaphores. I have to do more testing but am confident up to now. I did use a codesnippet with a quite sophisticated semaphore implemented and did not work as desired. Back on msdn I reread the hints to semaphores and implemented the easiest way you can do and now seems to work.

Moreno Airoldi: Thank you for your hints. I am no C# crack but sure I know that creating a new window (I only do this for testing purposes -> the second thread later on won't have own window) does not mean to have a new thread. I forked off a thread creating that window. After first semaphore approach did not work and I almost tried anything (I at least thought so) I doubted my own implementation (really different thread??? Smile | :) ) and additionally did read out the thread IDs ... and... they are different (after I knew this definitly I've been wondering why I really doubted that Smile | :) )) ). To make long story short: Definitly there are two different threads with two different thread IDs (that I can also identify in MSProcessExplorer what I also did)
The problem why I want to lock the whole function library is not because two threads are communicating to the same device (wouldn't be a problem at all), the point is that two threads might communicate to the same object on my hardware controller. Especially the command handling is critical. A command is written to a reserved data object in the shared memory of that controller. If values (= Commands) change, the controller will examine the new command, copy it to its command register and quit the command by writing something in another shared memory as a reply. So if one thread "sends" a command and is interrupted anytime before it is acknowledged, that that command has been accepted by the hardware controller, it might happen that the other thread starts to write to the shared memory and corrupts the command.
The application on PC is a "simple" visualisation of what is going on at my hardware controller. I believe it will be no problem to lock the whole funclib while a command is wtitten (there are also other shared memories that can also be read or written that I don't want to be corrupted, only half updated and then read out by other thread aso....). Integrity/correctness of Data is primary goal.
As you pointed out, this is no good practice, but untill we have to manage communication by shared memory objects (and using another function library by the manufacturer of the controller to access that memories) this seems most practical solution (don't really need more). We have implemented timeouts to avoid deadlocks.
We are planning to do communication by ourselves and creating a tcp protocol to do communication. We wont use shared memory then and I will definitly do more work to accomplish this goal in a more OO way Smile | :)

PIEBALDconsult: I did already use lock to lock the single functions. Unfortunatly this is not enough as I also wanted to implement a handshake to the communication. Goal is to encapsulate "sending a command" (and other read/write operations) in a function library so that any software engineer working on that project can easily use it without dealing with eventhandling. So what I try to do is to force my funclib to do asynchronous communication synchronously (just for the goal to achieve usability and stability). Locking the single functions is not enough (unfortunatly). I really have to lock the whole static object (that might be kind of "thread-safe" itself but not in conjunction with the hardware it communicates with and the communication procedure that it has to follow).
Thank you both once again for writing me a reply! Its always interesting and helpful to know how other software engineers approach such a problem. Keep on coding!

PS: Moreno Airoldi: 2+2=5 ... can't google the solution -> whats it about?
QuestionSQL Script Pin
kibromg15-Apr-09 0:54
kibromg15-Apr-09 0:54 
AnswerRe: SQL Script Pin
tom57200715-Apr-09 0:57
tom57200715-Apr-09 0:57 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:06
kibromg15-Apr-09 1:06 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:16
kibromg15-Apr-09 1:16 
GeneralRe: SQL Script Pin
Skymir15-Apr-09 2:35
Skymir15-Apr-09 2:35 
AnswerRe: SQL Script Pin
Dino Mulahusic15-Apr-09 1:05
professionalDino Mulahusic15-Apr-09 1:05 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:07
kibromg15-Apr-09 1:07 
GeneralRe: SQL Script Pin
Dino Mulahusic15-Apr-09 1:09
professionalDino Mulahusic15-Apr-09 1:09 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:13
kibromg15-Apr-09 1:13 
GeneralRe: SQL Script Pin
Ashfield15-Apr-09 1:24
Ashfield15-Apr-09 1:24 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:57
kibromg15-Apr-09 1:57 
GeneralRe: SQL Script Pin
Ashfield15-Apr-09 9:44
Ashfield15-Apr-09 9:44 
GeneralRe: SQL Script Pin
a.hamidy15-Apr-09 1:26
a.hamidy15-Apr-09 1:26 
AnswerRe: SQL Script Pin
Christian Graus15-Apr-09 1:27
protectorChristian Graus15-Apr-09 1:27 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:58
kibromg15-Apr-09 1:58 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 2:22
kibromg15-Apr-09 2:22 
GeneralRe: SQL Script Pin
tom57200715-Apr-09 2:30
tom57200715-Apr-09 2:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.