Home > Software engineering >  The process of how to make the event called exclusive access to an array.
The process of how to make the event called exclusive access to an array.

Time:09-29

My program often trigger multiple events almost at the same time, and these events call process to access the same array, how to avoid the two process changes at the same time array data before an error override? I used to imagine doing a tag, when a process view tag before access to an array, if the tag says there is no other access array process, to rewrite tag, access to an array, but also can appear after this process to see mark no problem, is about to rewrite the tag was another process to check the tag before, lead to think that you can access both process array, or lead to access conflicts,

CodePudding user response:

You use the multithreading?
Vb6 program under normal circumstances, can only handle one thing at a time,

CodePudding user response:

reference 1st floor Topc008 response:
you use the multithreading?
Vb6 program under normal circumstances, can only handle one thing at a time,

I don't know, I use winsock control, when there are multiple connections dataArivel (probably misspelled) event? Application of using multiple threads to handle these events?

CodePudding user response:

Has the problem of data packets arrive, you need to add the packet can distinguish between sequence tags

CodePudding user response:

Winsock include multithreaded -- -- -- -- -- - I guess ,

General situation:
1, TCP mode, do not need to own the subcontract to send, winsock automatically according to the current situation of the subcontract network to send, only needs to be on the receiving end receives the byte array in sequence splicing can;
2, if it is partitioned and use multiple winsock to send, you need to handle each piece of the order of the problem by themselves, how to send the order and receive order between the winsock there may be differences,

CodePudding user response:

The
reference 4 floor Topc008 reply:

Guess, that I am still under test,

CodePudding user response:

The
reference 3 floor bakw response:

@ bakw then send and receive data do you want to do a check for themselves and to prevent individual bit is inverted, TCP communications or TCP communications alone can prevent this kind of mistake?

CodePudding user response:

With multiple winsock receive multiple connection request, and will not be able to use an array,
You define an array to a class, and then create a winsock also create a class instance, not every winsock have an array of their own,

CodePudding user response:

Generally TCP communication bring the check, and don't need to himself, but the packet length is below 1.5 K, send and receive the order may be inconsistent, so if it is multiple packet data, need to confirm the serial number of the package

CodePudding user response:

Fyi:
 Private Sub SendCICMsg (tn As an Integer, s As String) 'lineA... 
Dim after the As a Double
On the Error Resume Next
After=Now + 15 #/24 #/3600 #
Do
DoEvents
If CICsending=1 Then
CICsending=tn
If CICsending=tn Then
CICstr=s
TimerCICsend. Enabled=True
The Exit Do
End the If
End the If
If Now & gt; After Then
LogErrMsg "SendCICMsg" + CStr (tn) + ", "+ s + 15 s overtime!" "
CICsending=1
The Exit Do
End the If
Loop
End Sub

CodePudding user response:

@ bakw, for example, I use the winsock control to a web server to initiate a download 1 m large file request, the server will not necessarily help you put good order in the each package? Don't winsock control to guarantee the order of each packet?

CodePudding user response:

references to the tenth floor ssxsone response:
@ bakw I, for example, using the winsock control to a web server to initiate a download 1 m large file request, the server will not necessarily help you put good order in the each package? Don't winsock control to guarantee the order of each packet?

Concrete is not very clear, remember to use winsock before download web data reception is very poor, later I convert winhttp to download, relief,

CodePudding user response:

And relevant Protocol (Protocol attribute), TCP is orderly, UDP is disorderly,

CodePudding user response:

Don't discuss, on the 9 floor I have already given the standard answer,
  • Related