Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Broker API - How to freeze zorro with multithreading & callbacks #469644
11/27/17 00:41
11/27/17 00:41
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
I'm not sure if this is a "lessons learned" thread or a "feature request" thread. I'll let jcl decide if he wants. laugh

Here's a code snippet that will freeze Zorro from the broker DLL plugin:

Code:
// various headers omitted
#define PLUGIN_VERSION	2
////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) BrokerOpen(char* Name, FARPROC fpError, FARPROC fpProgress)
{
	strcpy_s(Name, 32, "TEST Callback");
	(FARPROC&)BrokerError = fpError;
	(FARPROC&)BrokerProgress = fpProgress;
	return PLUGIN_VERSION;
}

extern "C" __declspec(dllexport) BrokerLogin(char* User, char* Pwd, char* Type, char* Accounts)
{
	std::thread tcp_listener_thread([&]() {
		BrokerProgress(0); // I want to trigger a tick read on a dedicated listener thread.
		BrokerError("hello world");
	});
	tcp_listener_thread.join();
	return 0;
}



So what happened here?

1) BrokerError and BrokerProgress both invoke Zorro functions.
2) Zorro invokes BrokerLogin on this test DLL.
3) BrokerLogin starts a new thread tcp_listener_thread.
4) BrokerLogin waits for the thread to return & rejoin.

Meanwhile at tcp_listener_thread...
1) BrokerProgress tries to call Zorro. It freezes here because the zorro thread is occupied with BrokerLogin.
2) If BrokerProgress were commented out, the thread would freeze at the very next line for the same exact reason as the last.

In practice, a listener thread would make callbacks when the Zorro thread is occupied or not occupied. A plugin writer would have to account for both cases.

Possible workarounds involve forcing callbacks on the Zorro thread only, or some combination of std::atomic<bool> and using class instances whose destructors indicate thread availability, for example.

In conclusion, I think it would be nice if one of these two things happened:
1) Revise the manual to indicate that callbacks should only be issued when the zorro thread is unoccupied and recommend workarounds, or
2) A dedicated Zorro thread listens to / queues broker DLL callbacks.

Re: Broker API - How to freeze zorro with multithreading & callbacks [Re: AndrewAMD] #469645
11/27/17 07:28
11/27/17 07:28
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Yes. Zorro functions can only be called in the Zorro thread. Not in a different thread. For some functions, it may work, but not for functions affecting the message loop, such as BrokerProgress.

Re: Broker API - How to freeze zorro with multithreading & callbacks [Re: jcl] #472571
05/05/18 14:54
05/05/18 14:54
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
jcl, following up from this old thread...

This is from the description of fpProgress:
Quote:
When the progress parameter is 0, Zorro will trigger a cycle for requesting a price quote.
Am I allowed to call BrokerProgress(0) from a separate thread? And at any time?

And to be clear, this is how I tell Zorro that I have new market data ready to be read, correct?

EDIT: Okay, so I found this:
http://www.opserver.de/ubb7/ubbthreads.p...true#Post459055

But there is no discussion regarding threads, so I am still unsure.

EDIT2: And if not, how am I supposed to be able to push data while on the Zorro thread?

Last edited by AndrewAMD; 05/07/18 15:06.
Re: Broker API - How to freeze zorro with multithreading & callbacks [Re: AndrewAMD] #472612
05/08/18 10:31
05/08/18 10:31
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
I believe brokerProgress(0) must not be called from a separate thread. At least there is no mechanism that would allow calling it from another thread.

Re: Broker API - How to freeze zorro with multithreading & callbacks [Re: jcl] #472614
05/08/18 11:16
05/08/18 11:16
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Do any of the other plugins trigger a price cycle? If so, how is it used, and under which DLL call? And finally, what is achieved by triggering the cycle from a Zorro thread?


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1