[TD71] Threads & events

Discussion forum about all things Team Developer 7.x
Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

[TD71] Threads & events

Post by Dave Rabelink » 11 Jan 2018, 09:21

This testcase is to implement TD threads synchronization using events.

It is using

CreateEventW
WaitForSingleObject
SetEvent

The sample has 2 background threads. Thread1 needs 1 second to perform its actions (just a sleep). Thread2 needs 250 milliseconds.
When running these threads without any sync, you will see that during thread1 execution, about 4 thread2 actions are performed, as expected.

So be able to sync them, so that one thread will only start doing the actions when the other thread is done (visaversa).


First I could not get the sample working. The threads kept waiting for eachother.
But I found the solution: you will have to set the KERNEL32.DLL ThreadSafe to YES.


ThreadSafe.png

Now, when using this, Thread1 will wait until Thread2 is finished and visaversa. This will go on indefinitely until the threads are stopped.

The sample has a checkbox to enable/disable the wait functionality to show the difference in output.

ThreadEvents_TD71.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1137
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

[TD71] Threads & events

Post by Dave Rabelink » 30 May 2018, 10:52

BUMP
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

tom_bond
Germany
Posts: 40
Joined: 09 Mar 2017, 09:20
Location: Germany

[TD71] Threads & events

Post by tom_bond » 30 May 2018, 16:29

Thank Dave!

Excellent job!
Thomas Janocha
FORMAT Software GmbH

SQLBase 9.0.1, 11.6, 11.7.4, 12.0.2, TeamDeveloper 6.1, 7.0.3, TD Mobile 2.1

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests