我正在玩Haskell线程,我遇到了在通道中传递延迟评估值的问题.例如,使用N个工作线程和1个输出线程,工作人员传达未评估的工作,输出线程最终为他们完成工作.
我已经在各种文档中看到了这个问题并看到了各种解决方案,但我发现只有一个解决方案可行,其余解决方案则没有.下面是一些代码,其中工作线程开始一些可能需要很长时间的计算.我按降序启动线程,这样第一个线程应该占用最长的,后面的线程应该更早完成.
import Control.Concurrent (forkIO)
import Control.Concurrent.Chan -- .Strict
import Control.Concurrent.MVar
import Control.Exception (finally, evaluate)
import Control.Monad (forM_)
import Control.Parallel.Strategies (using, rdeepseq)
main = (>>=) newChan $ (>>=) (newMVar []) . run
run :: Chan (Maybe String) -> MVar [MVar ()] -> IO ()
run logCh statVars = do
logV <- spawn1 readWriteLoop
say "START"
forM_ [18,17..10] $ spawn . busyWork
await
writeChan logCh Nothing -- poison the logger
takeMVar logV
putStrLn "DONE"
where
say mesg = force mesg >>= …Run Code Online (Sandbox Code Playgroud) 我需要帮助理解这个面试问题:
问:找到一个算法,在二元搜索树中找到给定节点的下一个节点(例如,顺序后继节点),其中每个节点都有一个到其父节点的链接.
父母是指有序的前任还是直接的父母?如何创建一个树,其中节点具有到根节点的链接或者有前导的链接?任何帮助理解下面的数据结构和程序将不胜感激......
解决方案(如表格中所示)如下所示:
public static TreeNode inorderSucc(TreeNode e) {
if (e != null) {
TreeNode p;
// Found right children -> return 1st inorder node on right
if (e.parent == null || e.right != null) {
p = leftMostChild(e.right);
} else {
// Go up until we’re on left instead of right (case 2b)
while ((p = e.parent) != null) {
if (p.left == e) {
break;
}
e = p;
}
}
return p;
}
return null;
} …Run Code Online (Sandbox Code Playgroud) 我在线程中运行的 Linux 中有一个阻塞读取。
在程序关闭期间,我想使线程脱离此读取。不幸的是,我无法使用轮询或选择并编写正确的代码,因为读取的文件是不实现轮询/选择功能的设备驱动程序。
作为临时解决方案,我当前通过 pthread_kill 向线程发送 SIGUSR1 信号,并从处理程序调用 pthread_exit。这会杀死线程并到目前为止有效,但我对解决方案不满意,因为信号可能出现在任何地方,而不仅仅是在读取中。
Linux 上有什么机制可以中断阻塞读取吗?
顺便说一句 - 我尝试从不同的线程关闭文件句柄,希望这会产生某种 IO 错误。不幸的是这个简单的解决方案根本不起作用。
我试图通过3种方式播放位于远程服务器上的FLV文件("crossdomain.xml"在该过程中不存在):
你猜怎么着?
结论:Flash的跨域安全性是无用的.
请告诉我我错在哪里,或者我只是帮助别人明白这种安全无用.
我想设置curl使用代理服务器.网址由html表单提供,这不是问题.没有代理,它工作正常.我在这个和其他网站上找到了代码,但它们不起作用.任何帮助找到正确的解决方案将非常感激.我觉得波纹管很接近,但我错过了一些东西.谢谢.
我在这里改编的波纹管代码http://www.webmasterworld.com/forum88/10572.htm,但它返回了第12行丢失的T_VARIABLE的错误消息.
<?
$url = '$_POST[1]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1)
curl_exec ($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
echo '<br />';
print_r($curl_info);
?>
Run Code Online (Sandbox Code Playgroud)
波纹管从卷曲到代理返回没有内容
<?
$proxy = "66.96.200.39:80";
$proxy = explode(':', $proxy);
$url = "$_POST[1]";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_HEADER, 1);
$exec = curl_exec($ch);
echo curl_error($ch);
print_r(curl_getinfo($ch));
echo …Run Code Online (Sandbox Code Playgroud) 我想在嵌套的静态接口中使用泛型类.我的目标是做这样的事情:
public class MyClass<T>{
private MyInterface task;
public static interface MyInterface{
void aMethod (T item);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:无法对非静态类型T进行静态引用.如果我做了一些更改(下面)我可以在接口中使用泛型类型,但是我想避免使用这种方法,因为写入它是多余的同一类2次:一次为MyClass,另一次为MyInterface.
public class MyClass<T>{
private MyInterface<T> task;
public static interface MyInterface<T>{
void aMethod (T item);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑:我想这样做:
MyClass c = new MyClass<String> ();
c.setInterface (new MyClass.MyInterface (){
@Override
public void aMethod (String s){
...
}
);
Run Code Online (Sandbox Code Playgroud)
要么
MyClass c = new MyClass<AnotherClass> ();
c.setInterface (new MyClass.MyInterface (){
@Override
public void aMethod (AnotherClass s){
...
}
);
Run Code Online (Sandbox Code Playgroud) 我需要一个类似于array_unique数组内部数组的函数.
案例 - 应该相等,但输出"不相等":
<?php
$arr=array(array('a',1),array('a',2));
$arr2=array_unique($arr);
if($arr2==$arr){
echo "equal";
}
else{
echo "not equal";
}
?>
Run Code Online (Sandbox Code Playgroud)
如何更改代码以使输出"相等"?
我有一张想要在屏幕上显示的图片(jpg).此外,图片应部分由透明效果覆盖.透明的封面应该是动态的.因此,例如每天都会显示更多的图片.这张图片展示了我的意思:

我有没有灰色封面的图片,并希望添加此封面,但步骤不同.
有人可以给我一个提示如何做到这一点.
C++ STL中有多少种类型的迭代器?截至目前,我知道这些:
还有更多吗?它们之间有什么区别?每个的限制和特征是什么?使用哪种类型?
php ×2
algorithm ×1
android ×1
array-unique ×1
binary-tree ×1
c++ ×1
class ×1
concurrency ×1
cross-domain ×1
curl ×1
flash ×1
flv ×1
generics ×1
gwt ×1
gwt-mvp ×1
haskell ×1
image ×1
inorder ×1
interface ×1
io ×1
iterator ×1
java ×1
linux ×1
mvp ×1
php-curl ×1
proxy ×1
pthreads ×1
security ×1
stl ×1
strictness ×1
transparency ×1
tree ×1