You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* There IS a 'onthreadmessage' attribute specified. Messages from
123
+
* this PHPthread to its parent (the MAIN process in this case) will
124
+
* be sent to the function "messages_from_thread1()"
125
+
*/
126
+
$thread1id =
127
+
phpthread_create(
128
+
$thread1,
129
+
array(
130
+
'onexit'=>"thread_exit_callback",
131
+
),
132
+
"threadproc",
133
+
null, /* No class instance or name, it's not a method */
134
+
array(3) /* The 2nd parameter received in "threadproc()", after it's PHPTHREAD class instance
135
+
* will be the number "3". Meaning this process wants THREE messages from it.
136
+
*/
137
+
);
138
+
139
+
140
+
if ($thread1id < PHPT_SUCCESS) {
141
+
echo"MAIN (PID: $main_id) - ERROR: [".phpthread_create_errmsg($thread1id)."] Failed to launch PHPthread!\n";
142
+
exit($thread1id);
143
+
}
144
+
145
+
146
+
/**
147
+
* NO 'onthreadmessage' attribute. Messages from this PHPthread will
148
+
* be sent to the target's (the MAIN process in this case) default
149
+
* message handler.
150
+
*/
151
+
$thread2id =
152
+
phpthread_create(
153
+
$thread2,
154
+
array(
155
+
'onexit'=>"thread_exit_callback",
156
+
'onmessage'=>"thread_message_handler",
157
+
),
158
+
"threadproc",
159
+
null,
160
+
array(1) /* We want ONE message from thread 2 */
161
+
);
162
+
163
+
164
+
if ($thread2id < PHPT_SUCCESS) {
165
+
if ($thread1) $thread1->kill();
166
+
echo"MAIN (PID: $main_id) - ERROR: [".phpthread_create_errmsg($thread2id)."] Failed to launch PHPthread!\n";
167
+
exit($thread2id);
168
+
}
169
+
170
+
171
+
echo"MAIN (PID: $main_id) - Running for 20 cycles. I will send a message to the first PHPthread at 6 cycles, and the second at 12. Then, I'll send them both 'quit' messages after my loop.\n\n";
172
+
173
+
for ($i = 0; $i < 20; $i++) {
174
+
175
+
$msg = phpthread_get_message(1000); /* Wait up to 1 second for a message */
0 commit comments