
12.07.2023, 21:15
|
|
Постоянный
Регистрация: 26.03.2016
Сообщений: 660
С нами:
5332594
Репутация:
163
|
|
Сообщение от reussssya
Решил проблему? Если да, то как?
C++:
Код:
namespace
app
{
class
gui
{
public
:
std
::
function
onButtonClicked
;
void
setText
(
std
::
string text
)
;
void
run
(
)
;
}
;
class
net
{
public
:
std
::
function
onTextReceived
;
void
sendTextRequest
(
)
;
void
run
(
)
;
}
;
}
// namespace app
int
main
(
)
{
app
::
gui gui
;
app
::
net net
;
gui
.
onButtonClicked
=
[
&
net
]
(
)
{
// нужно обеспечить безопасность потоков (mutex)
net
.
sendTextRequest
(
)
;
}
;
net
.
onTextReceived
=
[
&
gui
]
(
std
::
string newText
)
{
// нужно обеспечить безопасность потоков (mutex)
gui
.
setText
(
newText
)
;
}
std
::
thread gui_thread
{
std
::
bind_front
(
&
app
::
gui
::
run
,
gui
)
}
;
std
::
thread net_thread
{
std
::
bind_front
(
&
app
::
net
::
run
,
net
)
}
;
// ждём завершения потоков
gui_thread
.
join
(
)
;
net_thread
.
join
(
)
;
}
|
|
|